Add constant push velocity to player

Discussion in 'Plugin Development' started by Banjer_HD, Dec 4, 2019.

Thread Status:
Not open for further replies.
  1. I wan't to make a 'wind' effect so that a player is constantly being pushed to a direction (for example positive x).

    If I do it like this it will prevent the player from walking in the direction of the wind, a player cant sprint and is slow. It is also hard to walk 'against' the wind, player can't spring and is to slow to walk against it:
    Code:java
    1. public class OnPlayerMove implements Listener {
    2.  
    3.  
    4. @EventHandler
    5. public void onPlayerMove(PlayerMoveEvent e) {
    6.  
    7. Player p = e.getPlayer();
    8. p.setVelocity(p.getVelocity().add(new Vector(0.01, 0, 0)));
    9.  
    10. }
    11.  
    12. }


    Is there any way I can do this?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Banjer_HD What happens if you do it timer based?
     
  3. @timtower

    I tried this on command:

    Code:java
    1.  
    2. new BukkitRunnable() {
    3. public void run() {
    4.  
    5. Player p = Bukkit.getPlayer(pName);
    6. p.setVelocity(p.getVelocity().add(new Vector(0.01, 0, 0.01)));
    7.  
    8. }
    9. }.runTaskTimer(Main.getInstance(), 0, 1);
    10.  


    But a player can't move normally, it doesn't accelerate the player when it is sprinting so even when walking in the same direction of the wind, it is slower then without wind
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Banjer_HD You are adding and removing the wind here as well, so that is wrong.
    Is the start velocity the same as the end velocity in this case?
     
  5. @timtower
    Sorry, coppied the wrong code (that code was just for testing if I could sprint) :p
    I've eddited it now.
     
  6. Offline

    timtower Administrator Administrator Moderator

    Banjer_HD likes this.
  7. Offline

    timtower Administrator Administrator Moderator

    @Banjer_HD This might be a clientside / serverside issue. Not 100% sure though.
     
  8. Thanks for your answer!
    Does anybody have an idea on how to solve this?
     
Thread Status:
Not open for further replies.

Share This Page