Demo_ player movement (focus on animation settings)

Source: Internet
Author: User

usingUnityengine;usingSystem.Collections; Public classNewplayermove:monobehaviour {Private floatHor,ver; PrivateAnimator ANI; //Turn Speed     Public floatTurnspeed =Ten; voidAwake () {ANI= getcomponent<animator> (); }    voidUpdate () {Hor= Input.getaxis ("Horizontal"); Ver= Input.getaxis ("Vertical"); //MovingMove (ver); //Turn aroundTurn (Hor, ver); }    voidMove (floatver) {        if(Ver! =0|| Hor! =0) {            //find the actual distance            floatresult = MATHF.SQRT (Hor * hor + ver *ver); //setting the speed parameterAni. SetFloat (" Speed", Mathf.abs (result)); } Else {            //let the character stop movingAni. SetFloat (" Speed", -1f); }    }    voidTurn (floatHorfloatver) {        //If the player presses any one of the arrow keys        if(Hor! =0|| Ver! =0) {            //Get Direction vectorVector3 dir =NewVector3 (Hor,0, ver); //gets the four-dollar number represented by the direction vectorquaternion qua =quaternion.lookrotation (dir); //the player moves slowly to the rotation represented by the target four-dollar numberTransform.rotation =Quaternion.lerp (transform.rotation, qua, time.deltatime*turnspeed); }    }}

Demo_ player movement (focus on animation settings)

Related Article

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.