Solved Normal movement speed underwater

Discussion in 'Plugin Development' started by YoFuzzy3, Jan 18, 2013.

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

    YoFuzzy3

    Are there any reliable ways of doing this? If so please point me in the right direction. :)
     
  2. Well, you could do a player move event then check if there "in water" then set there vilocity.
     
  3. Offline

    YoFuzzy3

    What velocity would I set the player to though?
     
  4. Set it to what you feel is the right speed :p
     
  5. Offline

    Adamki11s

    YoFuzzy3
    Just keep modifying the velocity you add to the player until it feels normal, this is one of those things that unless someone has done it before you'll just have to figure out for yourself ;).
     
  6. Offline

    YoFuzzy3

    I've never done anything with Vectors before, could you explain how they work? :)
     
  7. Offline

    Adamki11s

    YoFuzzy3
    Sure. A vector quantity represents both magnitude (in this case speed) and direction. So to modify a players movement in minecraft you need to edit his velocity, which is represented by a vector object.

    Here is some example code. In your case you probably want to perform a check to see if the player is underwater and then edit his velocity.

    Code:java
    1.  
    2. Vector velocity = p.getVelocity();
    3. int xmod = 0, ymod = 1, zmod = 0;
    4. velocity.add(new Vector(xmod, ymod, zmod));//you can add or multiply
    5. velocity.multiply(2); //Probably what you want to use
    6. p.setVelocity(velocity);
    7.  


    https://github.com/Adamki11s/Extra-...Adamki11s/Extras/Player/ExtrasPlayer.java#L30
    That should help you check if the player is under water.
     
  8. Offline

    YoFuzzy3

    They both cause the player to have no control over their direction. For example if I change the y axis they'll just get shot up.
     
  9. Offline

    Adamki11s

    YoFuzzy3
    The code I gave you was just an example. Try setting their y velocity component to 0. Maybe that will stop them falling. But the issue of having no control is almost inherently linked to what you are trying to achieve in a way. As you can't detect key presses using the default Bukkit api.
     
  10. Offline

    YoFuzzy3

    I've tried many different velocities, it's always uncontrollable. I guess I can't achieve what I'm after using the Bukkit API.
     
  11. Offline

    Adamki11s

    YoFuzzy3
    Unfortunately I don't think so. Unless anyone can shed some insight.
     
  12. Offline

    chasechocolate

    player.setVelocity(new Vector(player.getLocation().getDirection().multiply(2)));? Completely writing this from scratch, so I have no idea if it will even work.
     
  13. Offline

    Adamki11s

    chasechocolate
    Ah yes I remember you can do that and it just takes them where the player is looking.

    YoFuzzy3
    That might be a viable solution?
     
  14. Offline

    YoFuzzy3

    I got the following code to give me a pretty good result.
    Code:java
    1. Vector velocity = new Vector();
    2. velocity = player.getLocation().getDirection().multiply(1.01);
    3. player.setVelocity(velocity);

    Although because of the limitation I think I'll make it something the player can activate/deactivate. Thanks for the help! :)

    Edit: It seems like no matter what I set multiply to it always gives the same speed. :confused:
     
Thread Status:
Not open for further replies.

Share This Page