Block Collision

Discussion in 'Plugin Development' started by confuserr, Jul 23, 2012.

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

    confuserr

    Trying to allow a player to climb up a tree (without ladders etc) by walking into it.

    Using the onPlayerMoveEvent to see if they are near to a Log

    Code:
    if(player.getLocation().add(0.5, 0, 0).getBlock().getTypeId() == org.bukkit.Material.LOG.getId()) {
                    System.out.println("Tree found");
                    player.setVelocity(player.getLocation().add(0, 1, 0).toVector());
    }
    
    I can't get the velocity right though. I've tried few ways now but basically ends up in a loop as it always detects them near wood (log), so increases their Y co-ordinate till they reach the very top of it.
     
  2. Hmm... you could try this:
    When player reaches the block near the log, use event.setTo() in the middile of the block (blockX() + 0.5, etc) and then every time player moves, he will try to move offset of that position, that way you can get where he wants to move, and calculate which way to go... if it moves towards the log, add velocity upwards, if he moves away, add velocity downwards... and always overwrite setTo() to the middle of the block until player is on top of another block and presses backwards OR there's no more log above and presses forward, then release him.
     
Thread Status:
Not open for further replies.

Share This Page