Why using transform.translate not rigidbody.velocity or .postion for movement

public class Mover : MonoBehaviour
float movesSpeed = 5f;
Rigidbody myrigidbody;
Vector3 moveable;

void Start()
    myrigidbody = GetComponent<Rigidbody>();

void Update()
    var moveX = Input.GetAxis("Horizontal") * movesSpeed;
    var moveZ = Input.GetAxis("Vertical") * movesSpeed;
    var moveY = myrigidbody.velocity.y;

    moveable = new Vector3(moveX, moveY, moveZ); 
    transform.position += moveable * Time.deltaTime;

// transform.translate(moveable);

Hi Jatin,

In many cases, there are multiple ways to make something work in Unity, and Rick cannot show all of them. If your code works, it’s a solution by definition. :slight_smile:

See also:

Thanks for your help ,
but I am watching rick from more than 1 year i think he never use anything that doesn’t have meaning i just want to know which is better way in particular condition.

If there are multiple ways, Rick needs to opt for one. Since he’s an instructor, he wants to teach a variety of techniques. There is not always a higher reason behind his decisions, and he also doesn’t want to convey the impression that his way was the only valid way to do things.

transform.position and transform.Translate give us the same result in this case. The difference between the two is that you do the maths for the translation yourself when using transform.position, and when calling Translate, Unity does the maths for you. Since this is a course, Rick wants to teach you how things are working behind the scenes. While that’s not always possible, it was in this case.

With the Rigidbody method, we would have the physics simulation control our player. At this point, we don’t want to dive too deep into the physics simulation because that could confuse beginners. We just want to move our object, and it should be obvious that we manipulate its position. That’s a decision Rick made as an instructor who wants to teach the fundamentals of Unity.

You wrote that you’ve been following Rick’s courses for more than one year. This means that you are not a beginner anymore, which is great. You are already familiar with Unity and C#, and you know alternative ways to accomplish things in Unity. Please feel free to apply your knowledge in your project. and explore alternative solutions. That’s fine. :slight_smile:

thank you so much mam for this brief explanation i am glad you replies

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms