I am trying to implement torque-shifting-based turning for an agent in my game. The code I am using is this (in FixedUpdate):
if(objective.set())
{
Vector3 targetAngle = objective.getPosition()-transform.position;
float angVar= Vector3.Angle(transform.forward,targetAngle);
Quaternion directMe=Quaternion.FromToRotation(transform.forward,-targetAngle);
if(angVar>5)
{
rigidbody.AddRelativeTorque(Vector3.up*directMe.eulerAngles.y/50);
}
}
This works as long as the objective approaches slowly and from the left
I feel like somehow a branch cut or something in the complex plane is preventing this from working in the other direction.
Is there a better way for a rigidbody to rotationally track another without using LookAt functionality? I’d like to do it all within the physics context.