java - Direction from origin for a certain distance -


I want to push a crowd from a direction to a certain distance, I right click on the crowd, but when I This code uses the distance to remove the crowd, depending on how close or far I am to the crowd.

  target.motionX = (target.posX- player.posX) * 0.5; Target.motionZ = (target.posZ - player.posZ) * 0.5;  

I know that the direction I face is needed to get that direction, then the crowd should take it away from a certain distance. I do not know how to do this.

Firstly you will need to find the distance:

  float xDis = target .posx - player.posX; Float zDis = target.posZ - player.posZ;  

If xDis is zero, calculate angle:

  float tangent = zDis / xDis; Float angle = Math Space (tangent); After that, set the length of your throw vector:  
  float length = 0.5;  

and then projection on two axes:

  float express = length * Math.cos (angle) * math. Signum (xDis); Boat zProj = length * Math.sin (angle) * math. Signum (xDis);  

And these are your motionX and speed parts.

If xDis is zero, then I think that you will need this special case.

  float xProj = 0; Boat zProj = length * math. Signum (zDis);  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -