I draw a rail on my central character with the direction of the front of my camera. I use Rigidbody.LookRotation to make the character return to that point, but it doesn't.
private void Update()
{
Physics.Raycast(transform.position + new Vector3(0, 3, 0), mainCam.transform.forward, out hit);
Quaternion lookrotation = Quaternion.LookRotation(new Vector3(hit.point.x,0,hit.point.z));
transform.rotation = Quaternion.Slerp(transform.rotation, lookrotation, Time.deltaTime * 2);
Debug.DrawLine(transform.position + new Vector3(0, 3, 0),hit.point);
Debug.Log(hit.collider.gameObject.name);
}
At first glance there are two points:
LookRotation expects a forward direction .. currently you only give it a position.
you would rather want to use e.g.
if(Physics.Raycast(transform.position + new Vector3(0, 3, 0), mainCam.transform.forward, out var hit))
{
var direction = hit.point - transform.position;
direction.y = 0;
var lookrotation = Quaternion.LookRotation(direction);
...
}
currently you also rotate just real slow. Assuming 60 Fps Each frame you interpolate with a factor of about 1/60 * 2 so about 0.033.. from the current towards the target rotation. So this gets even slower the closer you get to the target rotation.
You would rather either not multiply by Time.deltaTime but use a constant factor e.g. 0.5f
or use RotateTowards and provide a continous anglePerSecond * Time.deltaTime.