I need to make realistic human movement (3D) using mouse click.
- Get mouse click point using
Raycast
. - Smoothly
Slerp
toLookRotation
. - Move
transform.forward
.
Everything works fine, except I have problem with circular movement (close radius).
-
Example If dont move
transform.forward
whileSlerp
toLookRotation
orMoveTowards
instead oftransform.forward
it will be spinning like whirligig on circular movement. -
Example If do move
transform.forward
while whileSlerp
toLookRotation
it will distort trajectory of straight direct movement.
Is there any solution to move circular realistic (not spin like whirligig) and move straight direct when needed (not distort trajectory)?
I need straight movement from first example and circular movement from second.
if (Input.GetMouseButtonDown(1))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit[] hits = Physics.RaycastAll(ray);
foreach (RaycastHit hit in hits)
{
if (hit.transform.tag == "Ground")
{
DestinationPosition = new Vector3(hit.point.x, transform.position.y, hit.point.z);
DestinationRotation = Quaternion.LookRotation(DestinationPosition - transform.position);
break;
}
}
}
if (Vector3.Distance(transform.position, DestinationPosition) > 1)
{
transform.rotation = Quaternion.Slerp(transform.rotation, DestinationRotation, RotationSpeed * Time.deltaTime);
transform.position += transform.forward * MovementSpeed * Time.deltaTime;
//transform.position = Vector3.MoveTowards(transform.position, DestinationPosition, MovementSpeed * Time.deltaTime);
animation.CrossFade("run");
}
else
{
animation.CrossFade("idle");
}