#### Archived

This topic is now archived and is closed to further replies.

# How to determine if a position is in front of another?

This topic is 5270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, Let me explain: I want a player to be able to pick up items, but only those which are ''visible'' to the player. By visible I mean in front of the player (in an 180 degree or so slice of area from his left->front->right). I have the player''s forward vector, but he can obviously be rotated or face any angle. So, given the player position(x,y,z), forward vector(a,b,c) and an object position (ox,oy,oz), how can you determine whether the object position is in that 180 degree area, and therefore ''visible'' to the player? Thanks for any help with this! Mark

##### Share on other sites
This actually isn''t too difficult, since you''re checking a 180 degree span. If you create a vector V which goes from the player''s position to the object''s position (basically Vobject - Vplayer), and take the dot product between this vector and the player''s forward vector, your result will be >= 0 if the object is within the front 180 degrees (what you want), and < 0 if it''s behind the player. 0 is really a boundary value, where the object is right on the edge.

##### Share on other sites
Zipster is right.

My way of seing it:

First you move the objects position to be relative to the player.
Now, the players forward vector is a normal to a plane that goes through the origin (plane = n*{x,y,z} + d, where n is forward vector and d = 0 (origin is in the plane)). Inserting the new object pos in the plane by doing the dot product gets the (shortest) signed distance from the plane to the object. So if the distance < 0, the object is behind the plane and also behind the player. If the distance > 0, the object is in front.

Ah, maybe this is just confusing...

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 12
• 12
• 9
• 14
• 10
• ### Forum Statistics

• Total Topics
632654
• Total Posts
3007669
• ### Who's Online (See full list)

There are no registered users currently online

×