#Is there a way to check if my player is looking at something without a raycast or any physics?

1 messages · Page 1 of 1 (latest)

hybrid raven
#

You could check the angle between the direction from the player to the target position and the player camera's forward vector

faint cargo
#

hi @hybrid raven I solved it 🙂 I used the dot product

faint cargo
#

float angle = Vector3.Angle(transform.forward, sphere.transform.position - transform.position);

        if (Mathf.Abs(angle) < 10)
#

code if anyones interested, will mark it as solved

hybrid raven
#

blobOk
Keep in mind that this will check in a 20° cone, because you're comparing to 10° either side of the direction.

faint cargo
#

ah yes your right there

hybrid raven
#

Also, Vector3.Angle will always be between 0f and 180f, so using Mathf.Abs is unnecessary here.

faint cargo
#

oh ok thank you!

#

are you able to help me with something @hybrid raven

#

just a little something and if you dont know no worries then 🙂

hybrid raven
#

How am I supposed to know if I can help you, when you have not told me the issue?
Besides, if that was the reason you sent a friend request - please don't add me, just to ask me stuff.