recently began to use yunku. What is the difference between transform.position and transform.Translate? in both cases, the character moves. what is better to use?
1 answer
According to the documentation for Transform.Translate () , the method takes an optional parameter Space relativeTo = Space.Self , which determines the vector relative to which the object will move.
You can see the differences if you create three objects on the scene, to each of which you attach a corresponding script:
PositionMovement- moves the object, changing thetransform.position:void Update () { transform.Rotate(Vector3.up * 10f * Time.deltaTime); transform.position += Vector3.forward * Time.deltaTime; }TranslateSelfMovement- moves the object by calling thetransform.Translatemethod with theSpace.Selfparameter (used by default if omitted)void Update () { transform.Rotate(Vector3.up * 10f * Time.deltaTime); transform.Translate(Vector3.forward * Time.deltaTime); }TranslateWorldMovement- moves the object by calling thetransform.Translatemethod with theSpace.Worldparameter:void Update () { transform.Rotate(Vector3.up * 10f * Time.deltaTime); transform.Translate(Vector3.forward * Time.deltaTime, Space.World); }
As you can see, each object additionally rotates around a vertical axis.
By running this example, you will see that one object describes circles (with the TranslateSelfMovement script), while the other two are moving forward.

If you slightly adjust each script, replacing Vector3.forward with transform.forward , then all objects will describe circles, but the object with the TranslateSelfMovement script will have a different radius of circle:
