Raycast not accurate while running up / down a ramp

Hey,

i am trying to write a mouse control script. I have found some nice mouse script and modified it. It use the following code to determinate the target location and move the Player trough the animator into that position. But sometimes (especial on ramps) it miss the target and keep running. What is my mistake?

if (Input.GetMouseButtonDown(0) GUIUtility.hotControl == 0) {
			ray = Camera.main.ScreenPointToRay(Input.mousePosition);
				
				//Was haben wir getroffen ?
				if (Physics.Raycast(ray, out hit, 2000)) {
					Debug.Log(hit.collider.name);
					if (hit.collider.tag == "Ground") { 											// Haben wir den Level Boden getroffen ? Tag = Ground
						destinationPosition = ray.GetPoint(hitdist);								// Speicher die Position ab
					targetRotation = Quaternion.LookRotation(targetPoint - transform.position);		// Die Rotation zum Ziel
					//myTransform.rotation = targetRotation;
					myTransform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed);
					}
				}
}

Did i need to adjust my animations or is something with my raycast wrong?!

I hope someone of this great community can help - still learning unity.

Greetings

Luke

where are you getting “hitdist” from?

 destinationPosition = ray.GetPoint(hitdist);

personally I would have gone with getting the point from the returned RayCastHit rather than distance down the ray:

 destinationPosition = hit.Point;

I found a solution by my self. Yes you where right. the destinationPosition should be hit.point but also i calculated the distance between this points wrong. I hat to set the Y Values to 0. Cause iam using gravity and the Y Position doesnt matter.