How to smoothly launch player to a location(Or block coordianate if needed)

Discussion in 'Plugin Development' started by antflga, Feb 22, 2014.

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

    antflga

    I've been making a plugin for a big server project some buddies and I are working on, and I've been trying to launch players when they step over a block because our hub spawn is in a floating island theme/configuration. Now I have this code
    Code:
    if(p.getLocation().add(0, -1, 0).getBlock().getType().equals(Material.IRON_BLOCK)){
    loc.add(0, 2, 0);
    p.setVelocity(loc.getDirection().multiply(9));
    }
    And i have two problems. One, it doesn't always fire, two the launching is inconsistent and often goes way up or down. I'd like help with a launching system that is flexible (but can use coordinates if need be). I don't remember what server I was on but I do remember there were redstone blocks and when you would step on them it would launch you in the direction you were looking(my goal) and would play a sound.
     
  2. Offline

    Ironraptor3

    antflga use a PlayerMoveEvent, check if they have moved more than 1 block from their previous location. If they have:
    Code:java
    1. if (player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.IRON_BLOCK) {
    2. player.setVelocity(player.getVelocity().add( player.getLocation().getDirection().normalize().multiply(SPEED).setY(YSET) ));
    3. //where YSET and SPEED are custom variables
    4. }


    Alternatively, you could use a repeating event that starts when the server is started, and every few ticks checks if a player is standing on a block. Idk which would be more efficient.
     
Thread Status:
Not open for further replies.

Share This Page