Direction based on the forward facing camera

52 Views Asked by At

I'm trying to get if the 3d shoulder camera is facing the front of the player so I could stop the head from moving around.

I tried to do Vector3 Direction = targetConstraint.position - sourceObject.position; but that only worked if i was facing forward but if i turned around (180 Degrees) it does the opposite.

So I need a way to make it so I can detect whenever the camera in infront of the player.

1

There are 1 best solutions below

0
On

I just replaced it with a dot product

     // Get the camera's forward vector
     Vector3 cameraForward = sourceObject.transform.forward;

     // Get the vector between the camera and the player
     Vector3 playerToCamera = sourceObject.transform.position - targetConstraint.transform.position;
     Debug.Log(Vector3.Dot(cameraForward, playerToCamera));

     if (Vector3.Dot(cameraForward, playerToCamera) > 0)
     {
         targetWeight = orginWeight;
     }
     else
     {
         targetWeight = 0f;
     }

you might have to change the source and target constraint objects for it to work dot products are weird