Solved Launch a slime in the direction that the player is facing.

Discussion in 'Plugin Development' started by superchris05326, Apr 23, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    superchris05326

    I am developing a top down style minigame, and a part of it is being able to launch slimes. I want the slimes to launch in the direction that the player is facing, and I assume it's possible using the yaw/pitch values to calculate the correct vector, but I'm not sure how to do it. Also, just to clarify, I do not mean that I want to launch slimes in the direction that the player is looking, but the direction that the player's body is facing, since most people will play the game looking straight down. See image below.
    [​IMG]
    The red arrow being the direction that I want the slime to move.
    Any help would be greatly appreciated.

    Edit: After researching this for a bit, I think a better question is how do I use pitch and yaw to calculate a vector.
     
    Last edited: Apr 23, 2017
  2. Offline

    Zombie_Striker

    @superchris05326
    1. Using the Yaw, convert it to radians.
    2. use Math.cos() to get the X.
    3. Use Math.sin() to get the Z.
    4. Set the slime's velocity to be equal to the X and Z. Multiply those values if you need the velocity to be more drastic.
     
  3. Offline

    superchris05326

    This works! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page