Help player finding the location.

Discussion in 'Spigot Plugin Development' started by tigertmjv, Oct 19, 2019.

  1. First, Im still learning english so sory if my english is sh!tty.

    Im coding one plugin that help player finding the location. And i want every time player move, we send a title to player that tell him if he go the right way like: If player go the right way, the title is "Go Ahead" or player go the wrong way "Go right" or "Go left" or "Go back". My problem is i don't know how to let player know if player go the right way to send a title like this. Thank you !
  2. You can use the Location#distanceSquared method to determine if the player is getting closer or not, to determine the direction the player has to go you can use vectors.
  3. It's seem like I need to use Vectors but i really don't know how to use it. :(
  4. You can tell if a player is going North, East, South, West up, or down simply by checking PlayerMoveEvent, if the new block's location isn't the same as the old block's location. How I would set this up is I would add a command /addlocation "right"/"wrong" which stores the location you're at and works out which way you're facing.
  5. I seen all you two solutions but still have no idea how to use this for my case.
  6. It's not that difficult to be honest. If you were to work with vectors, get the vector between your player and your destination (subtract the player's location vector from the targetted location vector) and use Vector#angle(Vector) between the calculated direction to the destination and the player's direction. The value of that angle can then be used to determine which direction the player is going. 90 is turn left, 180 is turn around, 270 is turn right. (You probably want to check for a range of values, not exact ones.) All of that can be put in a scheduler; or in a PlayerMoveEvent (though I never really like to use that one, but.. that decision is up to you.) Here's a quick image to show you what that means a little more graphically.
    #7 Gadse, Oct 19, 2019
    Last edited: Oct 19, 2019
    • Like Like x 1