Efficient way to see if a location is within a player's client viewport

Discussion in 'Plugin Development' started by Ne0nx3r0, Apr 7, 2013.

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

    Ne0nx3r0

    Is there an efficient way to check if a given location is seen by a player? Specifically I want to track the location of a mob, and make it act differently if a player can see it than if no players can see it. (Kind of like a Mario Boo)

    This doesn't necessarily need to be perfect, just fairly efficient.
     
  2. Offline

    LazyLemons

    Code:
    ((Player)e.getEntity()).getTargetBlock(null, 500).getLocation();
    
    I guess since the distance of the TargetBlock is pretty far away, you might want to introduce a Cuboid and check the targetblock location with the cuboid's, for more accuracy.
     
  3. Offline

    Ne0nx3r0

    Well, I don't want to only get the exact location the player is looking at, but whether or not the location is visible on the player's screen. I was pretty tired when I wrote this last night, so I've tried to update my post for clarity.
     
  4. Clients can look both forwards and backwards depending on their camera style (F5), so there is no reliable way.

    EDIT:
    You could use entity.hasLineOfSight(entity) to check if entity (like player) can see another entity, shouldn't be called too often I guess, see its source code.

    Otherwise you could calculate yourself from the player's pitch and yaw some kind of pyramid shape that would be used to check if entity's location is in that shape...
     
  5. Offline

    Ne0nx3r0

    Digi That's a good point about the view ports... For my purposes I suppose I'd settle for an approximation of the front view, in which case any existing well made generic method for comparing 3d locations would work fine.

    I was hoping either there was something implemented I had missed, or someone might have an existing api/snippet laying around that accomplishes this.

    Hrm.
     
  6. Ne0nx3r0
    See my edit, there is a built in method.
     
Thread Status:
Not open for further replies.

Share This Page