I have this script:
//ASSUMING CAMERA TRANSFORM FORWARD OF (0,0,1)
Vector3 AssumedPos;
if (self.transform.position.z > target.transform.position.z)//(THIS EVALUTAION NEEDS TO CHANGE BASED ON CAMERA TRANSFORM FORWARD)
{
AssumedPos = new Vector3(
self.transform.position.x,
self.transform.position.y,
target.transform.position.z
);//(THIS RESULT NEEDS TO CHANGE BASED ON CAMERA TRANSFORM FORWARD)
Debug.Log("using clamped assumed pos");
}
else
{
AssumedPos = self.transform.position;
}
basically, assuming that camera is currently facing (0,0,1), this script detects if self.z has gone past the target.z, and if so it locks the assumed position.z to be the same as the target, while keeping the x and y the same.
Now I need it to be dynamic, and behave with the same general spirit of the code but the camera direction can be rotated, for example, the transform forward of the cam might be (1,0,0)
in this case the code should instead behave like this:
//ASSUMING CAMERA TRANSFORM FORWARD OF (1,0,0)
Vector3 AssumedPos;
if (self.transform.position.x > target.transform.position.x)//(THIS EVALUTAION NEEDS TO CHANGE BASED ON CAMERA TRANSFORM FORWARD)
{
AssumedPos = new Vector3(
target.transform.position.x,
self.transform.position.y,
self.transform.position.z
);//(THIS RESULT NEEDS TO CHANGE BASED ON CAMERA TRANSFORM FORWARD)
Debug.Log("using clamped assumed pos");
}
else
{
AssumedPos = self.transform.position;
}
I hope you can see the goal, basically I am trying to get the assumed pos to lock on the z axis if self has gone beyond the z position of the target, but if the camera rotates the variables are now mixed up and I can no longer do the comparison with .z pos
Also the direction of the camera is not always simple like this, it might be (1,0,1) for example.
I hope my problem is understandable and if someone can help me I would appreciate it! thanks