How to correctly position and rotate a gameobject taking into consideration the different methods available?
Can anyone diminish the confusion by giving an explanation of what each of the following functions does and in what context should it be used (best practices, etc.)?
- Transform.position/localPosition
“The position of the transform in
world space./Position of the transform
relative to the parent transform.”
- Transform.rotation/localRotation
“The rotation of the transform in
world space stored as a
Quaternion./The rotation of the
transform relative to the parent
transform’s rotation.”
“Unity stores rotations as Quaternions internally. To rotate an object, use Transform.Rotate. Use Transform.eulerAngles for setting the rotation as euler angles.”
-what does this mean? when do i use these 3 ways of rotating a gameobject?
- Transform.Rotate
“Applies a rotation of eulerAngles.z
degrees around the z axis,
eulerAngles.x degrees around the x
axis, and eulerAngles.y degrees around
the y axis (in that order).”-why would i use Transform.Rotate and not Transform.rotation/localRotation?
- Transform.Translate
“Moves the transform in the direction
and distance of translation.”-why would i use Transform.Translate and not Transform.position/localPosition?
- Transform.eulerAngles
“Only use this variable to read and set
the angles to absolute values. Don’t
increment them, as it will fail when
the angle exceeds 360 degrees.”
- Rigidbody.position
“Get and set the position of a Rigidbody using the physics engine.”
“Use this if you want to teleport a rigidbody from one position to another, with no intermediate positions being rendered.”
“The transform will be updated after
the next physics simulation step.”
- Rigidbody.rotation
“Get and set the rotation of a Rigidbody using the physics engine.”
“Use this if you want to teleport a rigidbody from one rotation to another, with no intermediate positions being rendered.”
“The transform will be updated after
the next physics simulation step.”
- Rigidbody.MovePosition
“Use this if you want to continuously move a rigidbody in each FixedUpdate, which takes interpolation into account.”
- Rigidbody.MoveRotation
“Use this if you want to continuously rotate a rigidbody in each FixedUpdate, which takes interpolation into account.”
- Rigidbody.AddForce
“Adds a force to the rigidbody.”-used when?
- Rigidbody.AddTorque
“Adds a torque to the rigidbody.”-used when?
The only big difference i know between these is that you want to use Rigidbody functions for physics game objects, that are not kinematic. other than that, they seem to achieve the same result.
Other comments about this subject are appreciated.
Links