"One of the Unity3d game development script notes: The effect of coordinate system selection on object Motion"

Source: Internet
Author: User

Time: September 24, 2016 17:38:21

Yexiaopeng Blog Park

In the world of Unity3d, its coordinate system can be divided into four kinds, the world coordinate system-worldspace The local coordinate system-localspace the screen coordinate system-screenspace viewport coordinates-viewportspace. The author himself is currently facing problems with the world coordinate system and the local coordinate system. In this paper, the influence of the two coordinate systems on the motion of the object is discussed, and the other coordinate system involves the explanation.

In the course of studying the Unity3d official example (Space War), the script that controls the movement of the meteorite found that the rotating meteorite was unable to move in a straight line. Among them, the control script for the linear motion of meteorites is:

1 void Update () {2         transform. Translate (Vector3.back * time.deltatime * speedmove); 3     }

After operation, the direction of movement of the meteorite was found to be chaotic, and the reason behind the inspection was that the meteorite rotation was added in order to make the effect of the meteorite lifelike, but in the process of rotation, the local coordinate system of the meteorite changed.

The function that controls the script line motion is used when the local coordinate system (transform. Translate by default, the local coordinate system is used in the input parameters, which causes the meteor to "fly".

WORKAROUND: Use the world coordinate system to control the linear motion of meteorites, modify the code as follows

1 void Update () {2         transform. Translate (Vector3.back * time.deltatime * speedmove, space.world); 3     }

Where Space.world represents the use of a world coordinate system, and the use of space.self or default means that the motion is in accordance with the local coordinate system.

"One of the Unity3d game development script notes: The effect of coordinate system selection on object Motion"

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.