Here will collect updates about how to control the move.
1. How to control the movement of characters by Wsad (i)
1 Public classPlayermovemeng:monobehaviour2 {3 //movement speed of the character4 Public floatSpeed=6f;5 //change in the movement of coordinates6 Vector3 movement;7 rigidbody playerrigidbody;8 //layer layers of plane that collide with Ray '9 intFloormask;Ten floatCamraylength=100f; One voidAwake () A { -Floormask=layermask.getmask (" Floor"); -Playerrigidbody=getcomponent<rigidbody>(); the } - voidfixedupdate () - { - //the control before and after WS + floatH=input.getaxisraw ("Horizontal"): - //control of ad around + floatV=input.getaxisraw ("Vertical") A Move (h,v); at Turning (); - } - //Implement Mobile - voidMove (floatHfloatv) - { -Movement. Set (H,0, v); inmovement=movement.normalized*speed*Time.deltatime; - //Use the moveposition of a rigid body to achieve character movement toPlayerrigidbody.moveposition (trandorm.position+movement); + } - //Steering Mouse the voidTurning () * { $Ray camray=Cameta.main.ScreenPointToRay (input.mouseposition);Panax Notoginseng Raycasthit Floorhit; - if(Physics.raycast (camray,out floorhit,camraylength,floormask)); the { + //get a vector of people and mouse clicks AVevtor3 playertomouse=floorhit.point-transform.position;
Gets the four-dollar number used for rotation between the character and mouse theQuaternion newrotation=quaternion.lookrotation (Playertomouse);
To achieve a person's turn over + playerrigidbody.moverotation (newrotation); - } $ } $}
2. Implement the camera to follow the characters of the script (no rotation direction)
1 PublicTransform Target;2 //Lens sliding Speed3 Public floatsmoothing=5f;4 //the distance between the camera and the character5 Vector3 offset;6 voidStart ()7 {8offset=transform.positiion-target.position;9 }Ten voidfixedupdate () One { AVevtor3 targetcampos=target.position+offset; -Transform.position=vector3.lerp (transform.position,targetcampos,smoothing*time.datle); -}
on how to control the movement of a character