Advertisement
Corosus

Untitled

Aug 31st, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. public void moveTowards(Entity ent, Entity targ, float speed) {
  2.         double vecX = targ.posX - ent.posX;
  3.         double vecY = targ.posY - ent.posY;
  4.         double vecZ = targ.posZ - ent.posZ;
  5.  
  6.         double dist2 = (double)Math.sqrt(vecX * vecX + vecY * vecY + vecZ * vecZ);
  7.         ent.motionX += vecX / dist2 * speed;
  8.         ent.motionY += vecY / dist2 * speed;
  9.         ent.motionZ += vecZ / dist2 * speed;
  10.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement