Transform movement related in Unity

Distance = direction * speed * time

Parameter 1: Indicates the displacement. Distance = direction * speed * time.
Parameter 2: Indicates the relative coordinate system. By default, this parameter is relative to its own coordinate system.

相对于世界坐标系的 Z轴 动  始终是朝 世界坐标系 的 Z轴正方向移动
this.transform.Translate(Vector3.forward * 1 * Time.deltaTime, Space.World);

相对于世界坐标的 自己的面朝向去动   始终朝自己的面朝向移动
this.transform.Translate(this.transform.forward * 1 * Time.deltaTime, Space.World);

相对于自己的坐标系 下的 自己的面朝向向量移动 (一定不会这样让物体移动) XXXXXXX
this.transform.Translate(this.transform.forward * 1 * Time.deltaTime, Space.Self);

相对于自己的坐标系 下的 Z轴正方向移动  始终朝自己的面朝向移动
this.transform.Translate(Vector3.forward * 1 * Time.deltaTime, Space.Self);

legend

If an object is rotated 45 degrees on the Y axis

(1) First take (0,0,1) in the world coordinate system, and then move to (0,0,1) in the world coordinate system, so it is moving in the positive direction of the Z axis of the world coordinate system

(2) First take the vector in the positive direction of yourself in the world coordinate system, which is the Z-axis direction that is slanted at 45°, and then move this direction in the world coordinate system, so you will eventually move towards yourself.

(3) First take the vector in the positive direction of the world coordinate system, which is the Z-axis direction inclined at 45°, and then move this direction in the own coordinate system, so it will eventually move towards the world coordinate system X Axis direction movement

(4) First take (0,0,1) in the world coordinate system, and then move to (0,0,1) in your own coordinate system, so you end up moving towards your own direction.

In fact, if you don’t study it carefully, you can just use the direction that comes with Vector3 as your own direction.

For example, moving towards the face

this.transform.Translate(Vector3.forward * 1 * Time.deltaTime);

 move upward

this.transform.Translate(Vector3.up * 1 * Time.deltaTime;

Guess you like

Origin blog.csdn.net/holens01/article/details/132639486