Home Game Development arithmetic – Determining if one thing is on the correct or left facet of an object?

arithmetic – Determining if one thing is on the correct or left facet of an object?

0
arithmetic – Determining if one thing is on the correct or left facet of an object?

[ad_1]

You first have to determine which route is ‘to the correct’ of your character. For thsi you will want to know which means the character is going through (uusally ‘route’) and which means is up usually (0,1,0) or it could possibly be the conventional of the airplane the character strikes round on.

proper = Vector3.Cross(route, up);

enter image description here

Next, we want a vector representing the relative place of the mouse click on and the character.

mouseDir= mousePos-charPos;

lastly, we have to verify if the angle between the correct vector and the mouseDir vector is bigger than or lower than 90 levels. If the angle is lower than 90deg the the mouse click on is on the correct, different sensible it’s on the left.

The dot product will return a optimistic worth if the angle is lower than 90, a unfavorable worth if the angle is bigger than 90.

if(Vector3.Dot(proper, mouseDir) <0){
   //do left hand stuff
}else{
   //do proper hand stuff
}

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here