Guest User

Untitled

a guest
Aug 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. private float findPlayerIntercept(Pair<Float> playerPos, Pair<Float> playerVel, int delta) {
  2. float hookSpeed = HOOK_THROW_SPEED * delta;
  3. Pair<Float> hPos = new Pair<Float>(position);
  4. Pair<Float> pPos = new Pair<Float>(playerPos);
  5.  
  6. // While the hook hasn't intercepted the player yet.
  7. while(Calculate.Distance(position, hPos) < Calculate.Distance(position, pPos)) {
  8. float toPlayer = Calculate.Hypotenuse(position, pPos);
  9.  
  10. // Move the player according to player velocity.
  11. pPos.x += playerVel.x;
  12. pPos.y += playerVel.y;
  13.  
  14. // Aim the hook at the new player position and move it in that direction.
  15. hPos.x += ((float)Math.cos(toPlayer) * hookSpeed);
  16. hPos.y += ((float)Math.sin(toPlayer) * hookSpeed);
  17. }
  18.  
  19. // Calculate the theta value between Stitches and the hook's calculated intercept point.
  20. return Calculate.Hypotenuse(position, hPos);
  21. }
Add Comment
Please, Sign In to add comment