Hey guys, I have not done Unity for quite some years now, so bare with me!
I have created a script for moving my player, but the player object stutters a lot when touching other objects, and is even able to glitch through walls at times when spamming random movement.
My best guess is that I need to use addForce, as transform.position will try to teleport into the wall and eventually gets pushed out. Can I prevent this or is it best going with addForce instead?
your guess is right, transform.position ignores colliders, so you will end up moving your player inside another collider and the physics will then try to resolve that which is the stutter/ pushing out
best way is to just go with the rigidbodies addforce
You should never directly manipulate Transforms to change the position/rotation of a Rigidbody2D as that is its role which is why it has an API dedicated to movement. It’s not there for any other reason.
If you want to have similar movement to setting transform.position, but still interact with colliders, you can set your Rigidbody’s isKinematic property to true and use the Rigidbody.MovePosition method instead.
A kinematic Rigidbody basically means it will still interact with colliders, but it will not move from external forces such as gravity and other collisions.