[ASK] Making an entity jump.

Discussion in 'Spigot Plugin Development' started by Gober, Jun 29, 2018.

  1. Is there a way to make an entity jump? Without using entity#setVelocity.
     
  2. Whats wrong with velocity? Its the best an easiest way to do it.
     
  3. entity.setVelocity(entity.getDirection().normalize().setY(Integer.MAX_VALUE) is what you want :LOL:
     
  4. I have a custom WASD plugin where if you press W it will set your velocity forward.
    But if you press:
    W : Set Velocity Forward
    Space : Jump & Set Velocity Up
    W again: Reset Velocity Forward and the Jump Velocity is Stopped.
     
  5. What about using getVelocity().add(vector) for all of your movement, then you can easily only modify the axis you want.

    Code (Text):

    event.getPlayer().setVelocity(event.getPlayer().getVelocity().add(event.getPlayer().getLocation().getDirection())); // moving forward
    event.getPlayer().setVelocity(event.getPlayer().getVelocity().add(new Vector(0, 0.5, 0))); // jumping
     
     
  6. Heres what I come with my mind:
    - When player jumps he had a Boolean set to true.
    - While the boolean is true. I add the vector 0,0.5,0 ?
    - Player ending up keep flying.

    Or:
    - Player jumps, I put hashmap<player, int> for live tick
    - Runs a runnable that heavily loops all player and get it's hashmap.
    - Reduce its hashmap int by 1.

    EDIT: Now I got the concept working but setting the Y of the Vector doesn't work!
    Here's what I do:

    Code (Java):
     myvector.add(new Vector(0, 0.04, 0));