About the movement of objects in unity in the corresponding direction of the local and world coordinate systems, respectively

Source: Internet
Author: User

Direction

Vector3 can define a three-dimensional vector that is referenced by the world axis, vector3.forward,vector3.up,vector3.right the unit vector of the z,y,x axis direction of the object's world coordinate system, or the three-dimensional unit direction vector, which is the vector

This.transform.forward,this.transform.up,this.transform.right corresponds to the unit vector of the current object in the z,y,x axis direction of the local coordinate system, or the three-dimensional unit direction vector, which is the vector

Distance

Update () {

float distance = This.first_move_speed * time.deltatime;//The distance traveled per second, is a scalar

......

Attention

Three-dimensional unit direction vectors multiply scalar distances to be used as a three-dimensional vector with length and direction

Moving translate functions (scalar in x-axis direction, scalar in Y-direction, scalar in Z-direction, specified coordinate system) can represent

The move function is a three-dimensional vector parameter

The addition and subtraction of object position is measured in three-dimensional vectors.

Method One

This.transform.Translate (0, 0,-distance, space.self);//local coordinate system for reference system
This.transform.Translate (0, 0,-distance, space.world);//World coordinate system for reference system

Method Two

This.c_ctrl. Move (-this.transform.forward * distance),//,this.c_ctrl is Unity's own character controller, in parentheses is a three-dimensional vector, three-dimensional unit direction vector by the scalar distance, the local coordinate system for the reference system

This.c_ctrl. Move (-vector3.forward * distance);//World coordinate system for reference system

Method Three

This.transform.position+=transform.forward * distance;//does a three-dimensional vector addition, three-dimensional unit direction vectors multiply the scalar distance, the local coordinate system is the reference system

This.transform.position+=vector3.forward * distance;//World coordinate system for reference system

About the movement of objects in unity in the corresponding direction of the local and world coordinate systems, respectively

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.