Character controller move to position

Hi all,

I searched and found the standard script.
But I want to use .move on the character controller so it moves directly towards the selected coordinate (h,v).
I have:

Plane playerPlane = new Plane(Vector3.up, character.transform.position);
Ray ray = cam.ScreenPointToRay (new Vector2(h,v));
float hitdist = 0.0f;
Vector3 targetPosition = Vector3.zero;

if (playerPlane.Raycast (ray, out hitdist))
{
Vector3 targetPoint = ray.GetPoint(hitdist);
targetPosition = ray.GetPoint(hitdist);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - character.transform.position);
character.transform.rotation = targetRotation;
}

movement = character.transform.position - targetPosition;

character.Move(movement);

It’s almost right!!, can anyone see anything blindingly obvious ? :slight_smile:
I wish the character to not slow down as it reaches it’s destination; and if it’s velocity is too high it over shoots.

Thanks

Did you ever find out what you were doing wrong here?

This is a post from TWELVE years ago.

markhula was last seen: Jul 3, 2012