click and move vihicle on terrain

Hi,

I have a tank game and want to make the controll for mobile like a click on the terrain and move the tank there. The tank has 3 axes and Wheelcolliders.

I already tried several things but allways run in the problem with different terrain heights.
As long as the terrain is flat it is no problem to move the tank, but if there is a small or then the tank get’s a strange behavior.

	IEnumerator MoveToPosition()
	{

		yield return null;
		while(Vector3.Distance(transform.position, target) > 3 ) {

			if(Vector3.Distance(transform.position, target)>3)
			{
				transform.LookAt(target); 
				Debug.Log (Vector3.Distance(transform.position, target));
			}

			rb.MovePosition(transform.position + transform.forward * 10 * Time.deltaTime);

			yield return null;
		}
		MoveToTarget= false;
		yield return null;
	

	}

tank

Try making putting the NavMeshAgent on the parent object, and the model of the tank in the child object. Then use the NavMeshAgent to drive the tank, and in the Update method of the child, rotate the tank to match the terrain.

See this thread for more discussion and sample code.