I’d like to rotate an object towards a Vector3 point without using LookAt. LookAt seems to instantly lock your view on the object. Does anyone know how to do this? I’m most familiar with C#, so if you could give an example using C# that would be great!
If I understand you correctly you want to rotate an object to ‘look at’ another object over time. One way to do it is with Quaternion.LookRotation and Quaternion.Slerp:
using UnityEngine;
public class SlerpToLookAt: MonoBehaviour
{
//values that will be set in the Inspector
public Transform Target;
public float RotationSpeed;
//values for internal use
private Quaternion _lookRotation;
private Vector3 _direction;
// Update is called once per frame
void Update()
{
//find the vector pointing from our position to the target
_direction = (Target.position - transform.position).normalized;
//create the rotation we need to be in to look at the target
_lookRotation = Quaternion.LookRotation(_direction);
//rotate us over time according to speed until we are in the required rotation
transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, Time.deltaTime * RotationSpeed);
}
}
or simply
transform.LookAt(Target)
Can you make it to a 2d game please???