Hello, I’m struggling with rotating an object to look at a camera.
I have an object which can be any orientation. I have methods to choose which Axis you want to be the “forward” direction(.i.e face the camera) and which axis to be the “Up” direction.
I can get 1 of these directions to work but not both. The way I am trying it is as so:
private Vector3 GetLookDirection ( DirectionAxis direction, Transform t )
{
switch ( direction )
{
case DirectionAxis.Green:
return t.up;
case DirectionAxis.NegGreen:
return -t.up;
case DirectionAxis.NegRed:
return -t.right;
case DirectionAxis.Red:
return t.right;
case DirectionAxis.Blue:
return t.forward;
case DirectionAxis.NegBlue:
return -t.forward;
default:
return t.forward;
}
}
void TestFunction()
{
transitionTransform.forward = GetLookDirection(DirectionAxis.Red, transitionTransform);
transitionTransform.up = GetLookDirection(DirectionAxis.Blue, transitionTransform);
}
transitionTransform should then contain the target rotation I can lerp to. This doesn’t work (obviously) as when I modify the forward it will also modify all other directions.
I’ve also tried things like:
transitionTransform.rotation = Quaternion.FromToRotation(Vector3.forward,GetLookDirection(DirectionAxis.Red,transitionTransform) * Quaternion.FromToRotation(Vector3.up,GetLookDirection(DirectionAxis.Blue,transitionTransform);
Which seems to yield the same result.
Basically, I want to flip the up and forward axes to point towards directions that I specify. I need some help, thanks!