Several common ways to move

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.