Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by Gober, Jun 29, 2018.
Is there a way to make an entity jump? Without using entity#setVelocity.
Whats wrong with velocity? Its the best an easiest way to do it.
entity.setVelocity(entity.getDirection().normalize().setY(Integer.MAX_VALUE) is what you want
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.
What about using getVelocity().add(vector) for all of your movement, then you can easily only modify the axis you want.
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
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.
- 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:
myvector.add(new Vector(0, 0.04, 0));