Toggle flight

Discussion in 'Plugin Development' started by the_merciless, Mar 5, 2013.

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

    the_merciless

    I have considered this option. Perhaps making them hold a certain item as fuel. Although I would still have to use fly mode. I don't understand velocity too well. Could someone show me how to make a player fly without using fly mode? For example, while holding shift the player will rise higher and when letting go they drop.
     
  2. Or you could make the item selection act as an enabler, which could also hold the cooldown value updated dynamically, but that'll be kinda complicated to keep track of.
     
  3. Offline

    minoneer

    You can set the players speed and direction like this:

    Code:java
    1. Vector playerDirection = new Vector(0,1,0); //this would be straight up.
    2. playerDirection.multiply(speed); //multiply by some number to set the speed you want.
    3. player.setVelocity(playerDirection);


    If you stil want the player to had to the direction he would usuall go to, I would use the Vector player.getLocation().getDirection() for the x and z coordinates, while setting the y value "manually". Just play a bit with those numbers untill you get the result you want.
    (btw, use the PlayerMoveEvent and check if the player is sneaking and maybe has some kind of "fuel" in his hand, as you suggested above)
     
  4. Offline

    the_merciless

    Im trying to avoid the moveEvent, i can however use PlayerToggleSneakEvent.
     
  5. Offline

    minoneer

    I'm not sure if that would work, since it only fires once. I know the PlayerMoveEvent shouldn't be used too often, but since you are altering the movement of a player, it would be a perfect fit. But sure, try the ToggleSneak first; if it doesn't work you can still use the other one.
     
  6. Offline

    the_merciless

    Yeah toggle sneak is perfect, hold it down to rise and let go to fall. it toggles on when u press down and toggles off when u let go.
     
  7. Offline

    minoneer

    It indeed does. I'm just not sure how you would go for the time inbetween, but I'm sure you'll figure it out :)
     
  8. Offline

    Lecrayen

    just allow flight when they jump once and let it stay allowed for a sec then disable it
     
  9. Offline

    the_merciless

    They wont receive damage, and that means i have to use the player move event which i am trying not to do.

    How can i test if the player has 1 or more of an item in their inventory,

    Code:
    if (p.getInventory().contains(new ItemStack(Material.COAL))){


    will check if the inventory contains a full stack of 64.

    Nevermind, found it.
     
  10. Offline

    the_merciless

    Ok, so I almost have it working perfectly, is it possible to edit just the y co-ordinate when setting vectors?
     
  11. Of course it is possible, but it depends on what code you're using.
     
  12. Offline

    the_merciless

    Code:
    double x = p.getLocation().getDirection().getX();
    double z = p.getLocation().getDirection().getZ();
    Vector vec = new Vector(x,1,z);
    vec.multiply(0.4);
    p.setVelocity(vec);
     
  13. Multiply only his Y coordinate, not the entire vector.

    p.setVelocity(new Vector(x, y * 2, z));

    Hmm, altough, I am unsure if setting X and Z to 0 will make the player stop instead of preserving momentum, it should... you should try that first :p
     
  14. Offline

    the_merciless

    doesnt y = 0 ?

    x and y as 0 will make the player unable to move

    I cant touch x and z at all otherwise im setting the players direction, im moving forward without even touching the w key.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page