It involves moving speed, main character object, target point, and Ray collision !~ [Javascript] var moveSpeed: int = 5; // player movement speed var player: Transform; // defines the Transform private var endposition of a character: Vector3; function Start () {endposition = player. transform. position;} function Update () {if (Input. getButtonUp ("LeftMouse") {// The LeftMouse is set in inputManager and the left-key value is mouse 0 PlayerMove ();} var targetposition = player. transformPoint (Vector3 (0, 48.8,-30); transform. position = targetposition; // the camera's Target location. The role of these two codes is to keep the character in the camera's field of view if (endposition! = Player. transform. position) {www.2cto.com player. position = Vector3.MoveTowards (player. position, endposition, Time. deltaTime * moveSpeed);} function PlayerMove () {var cursorScreenPosition: Vector3 = Input. mousePosition; // The Position of the mouse on the screen var ray: Ray = Camera. main. screenPointToRay (cursorScreenPosition); // emits a Ray at the position of the mouse's screen (the ray is X-ray now) var hit: RaycastHit; if (Physics. raycast (ray, hit) {if (hit. collider. gameObject. tag = "Terrain") {// set the Terrain Tag to Terrain endposition = hit. point ;}}}