How to get direction only in the x and z direction?

Discussion in 'Plugin Development' started by MrVeggieTacos, Feb 5, 2017.

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

    MrVeggieTacos

    Vector dir = p.getLocation().getDirection();
    dir.multiply(3.85);
    dir.setY(.5);
    p.setVelocity(dir);

    This code makes it so that when a player does the action specified in the code above it, it will boost the player forward and a little bit upward depending on where they are looking. The problem is, the boost does not shoot them forward if they are looking straight down or straight up, and this needs to be the case. So pretty much I need the boost to shoot the player forward the same amount no matter if they are looking up, down, or straight forward. Any ideas on how to solve this problem?
     
  2. Offline

    Zombie_Striker

  3. Offline

    MrVeggieTacos

    The player still wouldn't move forward though
     
  4. Offline

    Zombie_Striker

    @MrVeggieTacos
    Yes they would. There is nothing limiting the players XZ movement. Try it, and if that somehow happens, post your code.
     
  5. Offline

    mine2012craft

    Get the player's X and Z direction, set the Y direction to whatever, and then use them in the set velocity by vector.

    I would give a better example, but I'm on my phone, plus I'm eating Popcorn Chicken (Nom nom)
     
Thread Status:
Not open for further replies.

Share This Page