Rotation and displacement of Unity (1)

(1) About displacement

transform.position+=new Vector3(x,y,z);//Not affected by rotation//Move according to the world coordinate axis

or

transfrom.Translate(new Vector3(x,y,z));//Affected by rotation//Move according to the object's own coordinate axis

this

(2) About rotation

transform.eulerAnglers+=new Vector(x,y,z);

or

transform.Rotator(new Vector3(x,y,z));

When setting rotations using the .eulerAngles property, it is important to understand that although X, Y, and Z rotation values ​​are provided to describe the rotation, these values ​​are not stored in the rotation. Instead, the X, Y, and Z values ​​are converted to the quaternion's internal format. ——unity official

So regarding the rotation of an object, we generally use

transfrom.Rotator(new Vector3(x,y,z));

(3) About the rotation of objects

transform.RotateAround(point,axit,angleSpeed);

transform.RotateAround(new Vector(0,0,3),new Vector(0,0,1),2);

(4) Object gaze

transform.LookAt(new Vector3(x,y,z));

transform.LookAt(gameObjec.transform);//The position of the gaze target//The Z axis of itself is an arrow;

Guess you like

Origin blog.csdn.net/qq_56897801/article/details/129890122