Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private float findPlayerIntercept(Pair<Float> playerPos, Pair<Float> playerVel, int delta) {
- float hookSpeed = HOOK_THROW_SPEED * delta;
- Pair<Float> hPos = new Pair<Float>(position);
- Pair<Float> pPos = new Pair<Float>(playerPos);
- // While the hook hasn't intercepted the player yet.
- while(Calculate.Distance(position, hPos) < Calculate.Distance(position, pPos)) {
- float toPlayer = Calculate.Hypotenuse(position, pPos);
- // Move the player according to player velocity.
- pPos.x += playerVel.x;
- pPos.y += playerVel.y;
- // Aim the hook at the new player position and move it in that direction.
- hPos.x += ((float)Math.cos(toPlayer) * hookSpeed);
- hPos.y += ((float)Math.sin(toPlayer) * hookSpeed);
- }
- // Calculate the theta value between Stitches and the hook's calculated intercept point.
- return Calculate.Hypotenuse(position, hPos);
- }
Add Comment
Please, Sign In to add comment