- Home /
How would I find a point in front of my cam?
How exactly can I find a point directly in front of and at any given distance from my main cam? For example, I'm looking for a point that's exactly 2 units away from my main camera in the direction that it's currently facing. Are there any functions that could help with this?
Answer by aldonaletto · Nov 28, 2011 at 05:45 AM
That's a job for ViewportToWorldPoint: pass to it the vector (0.5, 0.5, distanceFromCamera), where 0.5, 0.5 means the center of the screen:
// returns a point exactly 2 meters in front of the camera: var point = Camera.main.ViewportToWorldPoint(Vector3(0.5, 0.5, 2.0));
Oops! I forgot the closing parenthesis! Answer is fixed now.
Thanks @aldonaletto one again you saved me. This worked perfectly for getting an aimpoint.
Answer by triangle4studios · Sep 18, 2020 at 11:51 PM
A much needed correction.
var point = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 2.0f));
Your answer
Follow this Question
Related Questions
Determine new position from magnitude & rotation/heading 1 Answer
Relative Rotation 1 Answer
How to calculate an end point of a line after rotating an angle in three-dimensional space? Thanks! 1 Answer
Vector3.Lerp moves other characters over network to (0, 0, 0) 1 Answer
How do I reset a GameObject pos / rot with a toggle? 0 Answers