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

Source: Internet
Author: User

There are two forward in unity, one is Transform.forward and the other is Vector3.forward.

For Vector3, it's just an abbreviation. There is no other meaning.

  • Vector3.forward, (0,0,1) abbreviation. //InTRANSFORM.TRANSLATE()InMakeUseWhen, no table Span class= "Contentbold" > Ming sit Mark , things Span class= "Contentbold" > body Bureau Ministry Span class= "Contentbold" > sit Mark , i.e. Span class= "Contentbold" > body from body Span class= "Contentbold" > positive ago square Span class= "Contentbold".
  • Vector3.right, (1,0,0) abbreviation.
  • Vector3.up, (0,1,0) abbreviation.

For Transform.forward, it represents the z-axis of the object's coordinate system of the current object pointing in the world coordinate system. (the blue axis in the world coordinate system).

If you use Transform.translate. It is important to note that Vector3 and transform are different.

1.spcae.world
Transform. Translate (Vector3.forward * time.deltatime, Space.world);
Transform. Translate (Transform.forward * time.deltatime, Space.world);

When local coordinates = world coordinates.

The coordinates of the authority! = when world coordinates. (rotate 30 degrees)

2.spcae.self
Transform. Translate (Vector3.forward * time.deltatime, space.self);
Transform. Translate (Transform.forward * time.deltatime, space.self);

When local coordinates = world coordinates.

The coordinates of the authority! = when world coordinates. (rotate 30 degrees)

so you will find that when using transform. Translate when the parameter is space.self. The direction of Transform.forward will be very strange. The reason is that the transform.Translate parameter Space.Self requires a directional vector of a local coordinate system , but Transform.forward is the direction vector of world coordinates.

So unless necessary, don't use this code:

Transform. Translate (Transform.forward * time.deltatime, space.self);

This will make your object move in a chaotic direction.

Should use:

Transform. Translate (Transform.forward * time.deltatime, Space.world);//or
Transform. Translate (Vector3.forward * time.deltatime, space.self);

Small question: Why rotate 30° whentransform. Translate (Transform.forward * time.deltatime, space.self); Is this code going to move the object in 60° direction?

First, the Transform.forward is the variable that automatically calculates the forward direction vector for the object's rotational value. At the same time Transform.forward is the direction of the z axis of the object coordinate system of the current object in the world coordinate system. The system calculates that the rotation value of the z-axis in world coordinates is 30° according to the physical local coordinate system, but you use transform. Translate and set the space.self according to the local coordinates movement, then, Transform.forward this 30° world coordinates rotation also according to the object's local coordinate system to convert the local coordinates, then two times 30°+30° The last thing we see is the object moving toward the 60° rotation of the world coordinates.

Unity3d the difference between Transform.forward and Vector3.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.