Solved Velocity Problems

Discussion in 'Plugin Development' started by Javlin, Dec 25, 2015.

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

    Javlin

    So basically, I'm using velocity to throw a player in the direction they are looking. The problem is, if the velocity is too fast, the server just doesn't move the player (as shown here). Is there any way to prevent this, without lowering the velocity? This is what I'm doing if it helps:
    Code:
    Vector v = p.getLocation().getDirection();
    v.setX(p.getLocation().getDirection().multiply(6).getX());
    v.setZ(p.getLocation().getDirection().multiply(6).getZ());
    v.setY(p.getLocation().getDirection().multiply(1.5).getY());
    p.setVelocity(v);
    
    Full code (as requested by @Zombie_Striker):
    Code:
        @EventHandler
        public void onInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                Vector v = p.getLocation().getDirection();
                v.setX(p.getLocation().getDirection().multiply(6).getX());
                v.setZ(p.getLocation().getDirection().multiply(6).getZ());
                v.setY(p.getLocation().getDirection().multiply(1.5).getY());
                p.setVelocity(v);
            }
        }
    
     
    Last edited: Dec 25, 2015
  2. Offline

    Zombie_Striker

    @Javlin
    Can you post full code? It actually looks like from the video that your detection system (Interactevent) is not being triggered properly.
     
  3. Offline

    Coopah

    @Javlin
    Right clicking air without an item won't work btw.
    Instead of multiplying each value, just do #setVelocity(p.getEyeLocation().getDirection.multiply(number);
    That will optimize your code.
     
  4. Offline

    Areoace

    Are there any errors? Try tracing where the problem goes wrong with System.out.println
     
  5. I think you'd rather want a vector. He uses 3 (2) different values.
    #setVelocity(p.getEyeLocation().getDirection.multiply(new Vector(6, 1.5, 6));
     
  6. Offline

    Xerox262

    Your problem is that you were looking straight, your y was 0 so it couldn't send you anywhere, it was trying but you were colliding with the floor and it was updating your velocity.

    Try getting if Y is < 1 then setting it to 1
     
  7. Offline

    Javlin

    I was doing this, but I needed to multiply each individually to get the effect I wanted.
    Implementing this now, thanks.
    Seeing if this works... hold on.

    EDIT: No luck :/
     
    Last edited: Dec 26, 2015
  8. Offline

    Xerox262

    Does your console actually say moving too fast? It normally shows up if it's the problem.
     
  9. Offline

    Javlin

    It does not say moving too fast, and taking a look at the values, the end velocity does not change when it doesn't work, and when I back up to make it work. I'm going to try and determine the velocity at which it doesn't work (per block away from destination). This way I can get the same effect, but with being close to blocks.

    EDIT: Solved, checked if player was right-clicking a block, and if so, set the x and z velocity to the distance between the player and block.
     
    Last edited: Dec 26, 2015
Thread Status:
Not open for further replies.

Share This Page