Public classplayercontroller:monobehaviour{Charactercontroller cc; [Serializefield]floatM_rotationspeed =10f; [Serializefield]Private floatSpeed =Ten; Quaternion M_targetdir; Vector3 Targetpos=Vector3.zero; BOOLisrotated =false; voidStart () {cc= getcomponent<charactercontroller>(); } voidUpdate () {if(Input.getmousebuttonup (0) {ray Ray=Camera.main.ScreenPointToRay (input.mouseposition); Raycasthit Hitinfo; if(Physics.raycast (Ray, outhitinfo)) { if(Hitinfo.transform.CompareTag ("Ground") ) {Targetpos=Hitinfo.point; Isrotated=false; M_rotationspeed=0;//start with the rotation speed because the value is superimposed on the bottom.Debug.drawline (Camera.main.transform.position, Hitinfo.point, Color.Red,Ten); } } } if(!cc.isgrounded) {cc. Move ((Transform.position+NewVector3 (0, - +,0)) -transform.position); } if(Targetpos! =Vector3.zero) {if(Vector3.distance (Targetpos, transform.position) >0.1f) {Vector3 dir= (Targetpos-transform.position). normalized; Dir*= Time.deltatime *Speed ; Dir.y=0;//lest you face the ground if(!isrotated) {M_rotationspeed+=5;//rotational speedM_targetdir =quaternion.lookrotation (dir); Transform.rotation= Quaternion.lerp (Transform.rotation, M_targetdir, M_rotationspeed *time.deltatime); if(Quaternion.angle (Transform.rotation, M_targetdir) <1f) {M_rotationspeed=1; Isrotated=true; }} cc. Move (dir); } } }}
Unity simply moves with a mouse click