Why not set the transform position instead of rb velocity?

Hello, It is still unclear for me when we should manage movements with the transform versus the rb velocity.

From what I understood, Rigidbody velocity modification should be done when there are collisions involved, so the movements is directly handled by the Physics engine, taking into account collisions.
But in that case, why didn’t we use Rigidbody as well for the player movement controls, since the player can also collide with the enemies ?

Thanks a lot to the team for this amazing tutorial, I feel that I have learned a lot here, I am so grateful for your work!

Hi Anis,

Welcome to our community! :slight_smile:

In many cases, there are multiple ways to make something work in Unity, and Rick and Gary cannot show all of them.

I do not know to which code you are referring but if it’s the Player code, Gary’s reasoning might have been that we want to have the full control over the player’s position. We do not have any physical behaviour in our game like “having the player bounce off”, so the player’s movement is predictable as it does not get affected by anything but our code. We also want to clamp the position values.

Is this the only way to solve this problem? It’s not. Using the Rigidbody2D would work as well. If you want to challenge yourself, please feel free to test your idea in your project.

Did this help? :slight_smile:


See also:

1 Like

Hi Nina,

Indeed I was talking about the Player code.

Actually I tried first to move the player around using the rigidbody, but by adding velocity there was inertia in the player movement, and I guess it’s not what we want in this arcade-ish game experience, hence there is no added value of using Rb.

Okay so the same way we could have used transform to move the projectiles, so the choice of Rigidbody in this tutorial was arbitrary.

Thanks a lot for your time and have a wonderful day :slight_smile:

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

Privacy & Terms