Click to move collision

I use a simple click to move script but my problem is with character and terrain, he falls down.

Any simple click with collision detection?

Do you mean your player topples over, or that he falls through the terrain?

If its the first, just set freeze rotation Y on the rigidbody
If its the second, make sure you have a collider and a rigidbody (IsTrigger Unchecked)

The second one,

i have on player Capsule collider, rigidbody but i dont see difference.

i use this script

using UnityEngine;
using System.Collections;
 
public class moveOnMouseClick : MonoBehaviour 
{
	private Transform myTransform;				// this transform
	private Vector3 destinationPosition;		// The destination Point
	private float destinationDistance;			// The distance between myTransform and destinationPosition
 
	public float moveSpeed;						// The Speed the character will move
 
 
 
	void Start () {
		myTransform = transform;							// sets myTransform to this GameObject.transform
		destinationPosition = myTransform.position;			// prevents myTransform reset
	}
 
	void Update () {
 
		// keep track of the distance between this gameObject and destinationPosition
		destinationDistance = Vector3.Distance(destinationPosition, myTransform.position);
 
		if(destinationDistance < .5f){		// To prevent shakin behavior when near destination
			moveSpeed = 0;
		}
		else if(destinationDistance > .5f){			// To Reset Speed to default
			moveSpeed = 3;
		}
 
 
		// Moves the Player if the Left Mouse Button was clicked
		if (Input.GetMouseButtonDown(0) GUIUtility.hotControl ==0) {
 
			Plane playerPlane = new Plane(Vector3.up, myTransform.position);
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			float hitdist = 0.0f;
 
			if (playerPlane.Raycast(ray, out hitdist)) {
				Vector3 targetPoint = ray.GetPoint(hitdist);
				destinationPosition = ray.GetPoint(hitdist);
				Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
				myTransform.rotation = targetRotation;
			}
		}
 
		// Moves the player if the mouse button is hold down
		else if (Input.GetMouseButton(0) GUIUtility.hotControl ==0) {
 
			Plane playerPlane = new Plane(Vector3.up, myTransform.position);
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			float hitdist = 0.0f;
 
			if (playerPlane.Raycast(ray, out hitdist)) {
				Vector3 targetPoint = ray.GetPoint(hitdist);
				destinationPosition = ray.GetPoint(hitdist);
				Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
				myTransform.rotation = targetRotation;
			}
		//	myTransform.position = Vector3.MoveTowards(myTransform.position, destinationPosition, moveSpeed * Time.deltaTime);
		}
 
		// To prevent code from running if not needed
		if(destinationDistance > .5f){
			myTransform.position = Vector3.MoveTowards(myTransform.position, destinationPosition, moveSpeed * Time.deltaTime);
		}
	}
}

Does he fall through the terrain as soon as you start?

If so, make sure the collider is above the terrain to start.

The movement code may cause it to fall through the terrain if you push the collider into the ground, but generally this doesnt happen unless youre pushing with quite a bit of force.

Also, moving a char with a rigidbody should be done via Rigidbody.MovePosition and Rigidbody.MoveRotation rather than Transform position functions

when i dont use a ThirdPersonCOntroler or CharacterMotor script characters is on air and don’t go on the ground, but there are some mounts , when i click up on mount player go inside of it, if i use charactermotor or tpcontroler script player dont stay on the air(like it must) but the problem with mounts still happen

I tried the following to player

  • Capsule collider, rigidbody, with “clickOnMove” script but nothing happens
  • rigidbody only with “clickOnMove” script but still no work
  • My Terrain has a terrain collider

first
How rigidbodies works, what values i should give to rigidbody.

second
Im looking for a simple script similar to ThirdCharacterControler but only for collision detection.

I think the problem is on “onMouseMove” script

*Sorry for my vbad english