Game Development Community

How to get the vector of the direction player is looking at?

by Ali Khan · in General Discussion · 10/16/2006 (12:14 am) · 1 replies

I want to get the direction the player is looking at. I actually want to check which object is in the player's LOS? In order to use Container.raycast(), we need to specify two points between which the raycast is done. I can specify one point as the player's location but need to get the other point in the LOS of the player but some distance away from it. Can anybody help me or suggest any better way of doing it?

#1
10/16/2006 (3:20 am)
Ali,

Assuming you are using script, the best way would be to use .getEyeVector(). This should return the direction the player (or rather, the eye node on the player) is facing.
For your raycast, your start point should be the player's eye node position (object.getEyePoint()). The end point should be the eye node position added onto the eye vector scaled by your target distance.
I.e. in pseudo code: raycast(.getEyePoint(), .getEyePoint() + (.getEyeVector() * distance)).