Get Target Entity

Discussion in 'Plugin Development' started by jojodmo, Jan 9, 2014.

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

    jojodmo

    I was wondering how I could get the player, or mob that was in the player's crosshair... For example, you can do it with blocks with:

    Code:java
    1. Location loc = p.getTargetBlock(null, 100).getLocation();


    So I was hoping for something a little like this:

    Code:java
    1. Entity entity = p.getTargetEntity(null, 100).getEntity();


    Thanks!
     
  2. Offline

    nuclearmissile

    You can get interact events, like if you right click an entity within block place range, but I don't think there's a built-in method to check entities in crosshairs. You will likely need to write your own hitscan, which is a bit tricky but not expert-level hard, so you'll do good to look up some tutorials on hitscans/raycasting.
     
Thread Status:
Not open for further replies.

Share This Page