Hi guys,
I’m having issues with trying to rotate a Rigidbody2D towards another object (slowly) using MoveRotation. I’ve been doing this using transform.rotation previously but performance-wise I’ve read it’s better to use MoveRotation.
This is the code I was using previously (in Update) to calculate the vector from the object to the target object and then rotate:
Vector3 diff = target.transform.position - transform.position;
diff.Normalize();
float rot_z = (Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg);
Quaternion newRot = Quaternion.Euler(new Vector3(0,0,rot_z - 90));
transform.rotation = Quaternion.RotateTowards(transform.rotation, newRot, Time.deltaTime * 150f);
I’m having difficulty trying to modify this code in a way that uses Rigidbody2D.MoveRotation and still achieves the same effect. Does anyone have any ideas?
Here’s the movement I currently have. Each frame the drones are moving in the forward direction while rotating towards an enemy. After they fire a shot the rotation is paused briefly.
