How to move the "Unity note" role

Source: Internet
Author: User

method One : Change the transform of the object

 Public class Exampleclass:monobehaviour {    publicfloat5;     // the move to follow the camera is written in Lateupdate.    void lateupdate () {        transform. Translate (00, Time.deltatime * speed );}    }

method Two : Use the displacement function of the rigid body moveposition ()

 Public classExampleclass:monobehaviour { Public floatSpeed =6.0f;    Vector3 movement; voidStart () {playerrigidbody=Rigidbody; }    voidfixedupdate () {//Role Control        floatH = Input.getaxisraw ("Horizontal");//Get Horizontal values        floatv = Input.getaxisraw ("Vertical");//get the vertical axis valueMove (H, v); }    voidMove (floatHfloatv) {movement. Set (H,0, V); Movement= movement.normalized * Speed *Time.deltatime; Playerrigidbody.moveposition (Transform.position+movement); }}

mode three : Change the speed of the rigid body rigidbody.velocity. Velocity is a vector and has directionality.

 public  class   Exampleclass:monobehaviour { //  Get the joystick value  float  movehorizontal = Input.getaxis ( " horizontal  "      float  movevertical = Input.getaxis ( vertical   "     );  //  change speed  rigidbody.velocity = new  Vector3 (movehorizontal, 0.0f , movevertical) *  speed;}  

How to move the "Unity note" role

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: 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.