Using vectors to throw a player relatively?

Discussion in 'Plugin Development' started by ZephireNZ, Jun 26, 2013.

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

    ZephireNZ

    I currently have this code:

    Code:java
    1. public void jump(Player player, Double multiplier) {
    2.  
    3. double pitch = ((player.getLocation().getPitch() + 90) * Math.PI) /180;
    4. double yaw = ((player.getLocation().getYaw() + 90) * Math.PI) / 180;
    5. double x = Math.sin(pitch) * Math.cos(yaw);
    6. double z = Math.sin(pitch) * Math.sin(yaw);
    7. Vector vector = new Vector(x, 0, z);
    8. player.setVelocity(vector.multiply(multiplier).setY(0.8));
    9. }


    It works. When the function is run (with command), it will throw me forward relative to my cursor. However, odd things happen. Often I will veer to the left/right more than I want to, hence throwing me off course. Also, I approach/reach the speed limit in bukkit when I use a multiplier of ~20.

    So, can somebody tell me why this veers, and maybe how to fix it? And it'd be great to know how to get rid of "ZephireNZ move to quickly!", as it cancels the movement and hence ruins the effect. I've also tried using the "DisableMovingTooQuickly" plugin, to no avail.
     
  2. Offline

    foodyling

    I'd use player.getLocation().getDirection() instead of all the long code, then set the y vector to 0, and then multiply it, also I've noticed that multiplying a vector to a high velocity seems to make a entity veer to the left (noticed it with arrows), on the server the entity will be in the correct location, but in the game it will make it veer. I'm guessing that the player gets veered because of the way the game handles the high velocities, afaik, there isn't a real way to fix this (I'm probably wrong).
     
  3. Offline

    ZephireNZ

    When I say veer, I mean the player really veers. A screen shot for reference:
    http://imgur.com/uPLXynm
    I shot an arrow moments before going in that same direction. The leftmost (46.41) is where the arrow went, the rightmost (49.57) is where I landed. That kind of veering is unacceptable for what I'm trying to do.

    Edit: Oh, and I started on the lone pressure plate on the black wool.
     
  4. Offline

    foodyling

    Does it throw the arrow/player in that direction or does it start curving like a parabola?
     
  5. Offline

    ZephireNZ

    It goes straight. I did a more detailed and scientific test, and the results aren't very good:
    http://i.imgur.com/6IF2At6.png

    The lapis block at the bottom was where I would go from, point at each colour and recording my landing point. All of them went straight with not curve (as far as I could tell).
     
  6. Offline

    foodyling

    Yeah, that doesn't seem to be very good, which code are you using, yours or the player.getLocation().getDirection(), if you're not using getDirection() and multiplying it, try that and see if it works
     
  7. Offline

    ZephireNZ

    Yeah, I was using this:
    Code:java
    1. Vector look = player.getLocation().getDirection();
    2. player.setVelocity(look.multiply(mult).setY(1))
     
  8. Offline

    ZephireNZ

    Bump :3
     
  9. Offline

    Rocoty

    I don't know this, but I THINK that player.getLocation().getDirection() gets the body direction, and the body might be pointing in a different direction than the head. So I'd try player.getEyeLocation().getDirection();

    See if that gets you anywhere
     
  10. Offline

    LucasEmanuel

    Rocoty
    "player.getLocation().getDirection()" does not give him the direction of the body.

    The only difference between those two methods is that the eyelocation is one block above the other one. :)
    source
     
    Rocoty likes this.
  11. Offline

    Rocoty

    LucasEmanuel
    Oh okay. Can't argue with that.

    I just thought that since the head can be twisted slightly differently than the rest of the body, that they would have different directions. Seems I was wrong, then.
     
Thread Status:
Not open for further replies.

Share This Page