Hello.
I would like to ask you, if we have a player his coordinates: X, Y, Z and float angle how can we check if looking for a direction and for example “spawn” something at coordinates where player is looking?
Hello.
I would like to ask you, if we have a player his coordinates: X, Y, Z and float angle how can we check if looking for a direction and for example “spawn” something at coordinates where player is looking?
Hey,
With only one angle, you can convert to a 2D unit vector, the 2D direction:
x = cos(Angle)
y = sin(Angle)
For a 3D Vector, you will need 2 angles, pitch and yaw, then convert using a similar way:
cosPitch = cos(pitchAngle)
sinPitch = sin(pitchAngle)
cosYaw = cos(yawAngle)
sinYaw = sin(yawAngle)
directionX = cosPitch * cosYaw;
directionY = cosPitch * sinYaw;
directionZ = sinPitch;
Once you have this unit vector you can spawn something at the distance you want.
having these sin x cos y thingy(call it vecP) and check point(CP) and the point you want to look at(LP): you calculate the dot of two vectors: positon dot(vecP, Normalize( vectorAB( LP, CP) )) and if its negative then its facing.. additionally it cant be smaller than -1