How to get Player that a I am looking at?

Discussion in 'Plugin Development' started by r0m3x, Dec 5, 2016.

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

    r0m3x

    Hi im trying to make a plugin so if Player1 holds a wither star and Player1's Cursor is on Player2 and Player1 right-clicks they swap locations, I was thinking maybe PlayerInteractEvent or something the look for the Action.RIGHT_CLICK_AIR. Is this possible? Ill try to respond as fast as possible.

    Thanks, r0m3x
     
  2. Offline

    Zombie_Striker

    @r0m3x
    1. On player interact
    2. If the player has a witherstar.
    3. Get the player's direction and the player's current location.
    4. build a while loop.
    5. Every time it loops, add the direction to the current location. Each time it loops, check if there a player within 0.5 Meters of that location. If so, the player is looking at that player.
     
  3. Offline

    r0m3x

    I know how to do the wither star thing but how would I get if the player is looking at a player or not?
     
  4. Offline

    Zombie_Striker

    @r0m3x
    If you're asking for code, you will not get it. We are here to help you, not write your plugin for you. If you have a question about a specific step, post what you tried (try to do the step before posting) and what does not work/ what confuses you.
     
  5. Offline

    mythbusterma

    @r0m3x

    If you Google around, I'm pretty sure someone has already written the code for this.
     
  6. Offline

    renaud444

    Try what was said before, but maybe also try normalizing the player's direction before applying any mathematics to it?
    The Vector.normalize() method. What it does, from my understanding, is take a vector and set its magnitude to 1, but in the same direction. This will make things a bit easier, I guess. That's all I'll give you in terms of code.
     
  7. Offline

    Scyntrus

    What you need to do is obtain the bounding boxes of all nearby players within whatever range you want and apply a ray-box intersection algorithm.
     
Thread Status:
Not open for further replies.

Share This Page