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!