Hi,
I’m trying to rotate an object only on its Y-axis in order to look at my player all the time, (like a turret motion)
I have tried this code:
var step = speed * Time.deltaTime;
Vector3 targetDir = target.position - transform.position;
Debug.DrawRay(transform.position, targetDir, Color.red);
Model.rotation = Quaternion.LookRotation(targetDir, Vector3.up);
and this one:
var lookPos = target.position - transform.position;
lookPos.y = 0;
var rotation = Quaternion.LookRotation(lookPos);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
But my object still rotates on all axis as seen on this image:
Any idea on how I can achieve this behaviour?