I. via character controller (role controller component) 1.SimpleMove public bool Simplemove (Vector3 speed);
The speed on the Y axis is ignored, and the return value indicates whether to land.
Charactercontroller ch; // get component ch = getcomponent< Charactercontroller> (); // Get the player's horizontal and vertical input Vector3 movedir = new Vector3 (Input.getaxis ( " horizontal "", 0 , Input.getaxis ( " vertical " // convert to world coordinates movedir = transform. Transformdirection (Movedir); Ch. Simplemove (speed *movedir);
2.move Public collisionflags Move (Vector3 motion);
Moving the controller through external forces and sliding along the collision body is limited only by collisions, regardless of gravitational effects.
Two. Move by animation, you need to tick apply Root Motion 1.BlendTree (1D)
First need to have a create a blendtree, this blendtree need to have three animation animation segment, outside there is an idle animation, used to switch between Blendtree, we can name this blendtree run, Run contains three animated segments, Run,runlift,runright (there is no backward animation);
Then we need to declare two parameters, one speed:float, to control from idle to run, the other for direction:float, to control 1D Blendtree, Runlift -1,run for 0,runright to 1, The parameters here are basically set to complete.
Then the conversion between idle to run, conditions set to speed, when greater 0.1, switch to run,less 0.1 switch to idle,
The last part that needs to be implemented in the code is the code (a little bit primitive ...). )
void Update () { animator. SetFloat (HS. Speedfloat,h*h+v*v); Animator. SetFloat (HS. directionfloat,h,directiondamptime,time.deltatime); }
Several common ways to move