Advertisement
vedi0boy

(java) Calculation to make player follow mouse(doesn't work)

Sep 24th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. Xdif = Anaglyph.mouseX - playerX-25;
  2. Ydif = Anaglyph.mouseY - playerY-25;
  3.  
  4. angle = Math.atan2(Ydif, Xdif) * 180 / Math.PI;
  5.  
  6. dX = Math.cos(angle * Math.PI/180) * 10;
  7. dY = Math.sin(angle * Math.PI/180) * 10;
  8.  
  9. playerX = ((playerX-mouseX)*(playerX+dX-mouseX) > 0 && playerX != mouseX) ? playerX+dX : mouseX;
  10. playerY = ((playerY-mouseY)*(playerY+dY-mouseY) > 0 && playerY != mouseY) ? playerY+dY : mouseY;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement