Unity3d the difference between Vector3.forward and Transform.forward!

Source: Internet
Author: User
Tags translate function

Original connection:

http://blog.csdn.net/kaluluosi111/article/details/17206655

There are 2 forward in the Unity3d, one is Vector3.forward and Transform.forward, and these two forward are actually quite different from each other. The difference between them is mainly reflected in the different coordinate system.



We compare the performance of the forward of the Vector3 and transform two vectors in the self and world coordinate systems, and we use the Transform.translate function to verify. .

Note: self-coordinates! = World coordinates means that the two coordinate systems do not overlap.


Self own coordinate system--space.self

Vector3.forward


Transform.forward


I am confused here, why the Transform.forward turn to their own coordinates will have such a strange result.




After drawing the picture above, I finally understood.

The transformation of the Self's own coordinate system is this:

Move the vector you want to convert to the target axis, as opposed to the world axis.


It's in Transform.forward.



So here's a summary of the difference between Vector3.forward and Transform.forward.

The value of Vector3.forward is always equal to (0,0,1).

The value of Transform.forward is equal to the Z axis of the current object's own coordinate system pointing at world coordinates and therefore not necessarily equal to (0,0,1), but its magnitude length is 1.

This is why, when Transform.forward is converted to self's own coordinate system, this is the result.


The situation on the world coordinate system--space.world is the exact opposite.


Therefore, to move the object forward, on the transform.translate () and directly modify the transform.position, the difference is quite large.


Transform.position itself is the world's coordinates.

1, transform.position+= Vector3.forward

is equal to the z-axis of the world coordinates forward.

2, Transform.position+=transform.forward

is equal to the z-axis of the object's own coordinate system.


3, Transform.translate (vector3.forward,space.self)

is equal to the z-axis of its own coordinate system forward.

The effect is equal to 2.

4, Transform.translate (transform.forward,space.self)

The results of the above-mentioned wonderful work are caused by this usage, and it is not advisable to use this usage for special needs.

5, Transform.translate (Vector3.forward,space.world)

is equal to moving the object along the z axis of world coordinates.

The effect is equal to 1.

6, Transform.translate (Transform.forward,space.world)

is equal to moving the object forward in the direction of the z axis of the object's own coordinates in world coordinates (equivalent to the object moving along its own z axis).

The effect is equal to 2.

Unity3d the difference between Vector3.forward and Transform.forward!

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.