Solved Check if Player/Horse is Walking Backwards?

Discussion in 'Plugin Development' started by TheHandfish, May 17, 2014.

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



    I'm working on a plugin that bounces the player back if he enters a cuboid and is not heading south. It's a race line, so obviously, I don't want the player going back and forth across it to win the race easily. The problem is that if the player/horse backpedals into the line after crossing it, it won't bounce him since all it does is a getYaw test. I tried doing a getVelocity().getX() test, but it didn't work. I also tried getDirection(), but that bounced me back no matter how I entered it (except, ironically, backpedalling.

    1. if(isInRaceline(p) /*Checks for the public static Cuboid to see if the player is in it, returns true if player is, if else, returns false.*/)
    2. {
    3. if(!p.getMetadata("playerInLine").get(0).asBoolean())
    4. {
    5. if(p.getLocation().getYaw() < 90 && p.getLocation().getYaw() > -90)
    6. {
    7. p.sendMessage("§aRight way!");
    8. p.setMetadata("playerInLine", new FixedMetadataValue(plugin, true));
    9. }
    10. else
    11. {
    12. p.setVelocity(p.getVelocity().multiply(-4));
    13. if(p.getVehicle() != null)
    14. {
    15. p.getVehicle().setVelocity(p.getVehicle().getVelocity().multiply(-4));
    16. }
    17. p.sendMessage("§4§oWrong way! Turn around.");
    18. }
    20. //p.sendMessage("§aDebug: §bPlayer in raceline!");
    21. }
    22. }
    23. else
    24. {
    25. p.setMetadata("playerInLine", new FixedMetadataValue(plugin, false));
    26. }

    Bump. >_>

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 8, 2016
  2. Offline


    You could keep track of the player's previous and current blocks, and compare their locations.
    RAFA_GATO_FOFO likes this.
  3. Offline


    Check which direction they are moving and then their yaw/pitch.
  4. Offline


    ZeusAllMighty11: I'll try that.

    Napkin222: I literally said I tried that already. :p Can I see an example of what you mean?
  5. Offline


    Solved. Thanks for the help! I already was using metas to record the player's last location, so I just compared that to event.getTo(). :)
Thread Status:
Not open for further replies.

Share This Page