Should I move a character using physics?

Hello, I’m new to unity. I was wondering what is the best way to move a character in a 2d game whether it’s platformer or top-down. I’ve watched some youtube videos and they all move the character by manipulation it’s velocity in the FixedUpdate function. But, as far as I know, moving a character using physics is not a great idea. But, what would be the alternative in unity? and is there some kind of tutorial or asset for that?

The alternative is to simply set the transform.position wherever you want it to be on each frame. And I think you’re right: in most cases, this is much better than wrestling with the physics engine.

Perhaps this article on 2D animation methods in Unity will make it clearer.

I just do the following in my gameobject(player) update method:

float hrz = Input.GetAxis(“Horizontal”);
float vrz = Input.GetAxis(“Vertical”);
transform.Translate(hrz * Time.deltaTime, vrz * Time.deltaTime, 0);

And your character is Kinematic?

If you use a Rigidbody then it is best to use Rigidbody.MovePosition to move it. Using Transform.Translate will simply teleport it to a new position regardless of physics and the next time physics reads that rigidbody it’s going to be pretty confused and possibly have a difficult (impossible) time trying to resolve any collisions it might have created whereas MovePosition will sort these out first and try to move it as reasonably as possible without exploding the whole simulation.

So it’s really one or the other, either make a controller using a rigidbody and use physics or do it with no rigidbody and use transform.

2 Likes

My character has no physics attached to it. We are just moving its position.

But without a rigidbody, how can it detect collisions?

You would need to do roll your own collision detection without rigidbody, but you can still have a rigidbody.

Depends on how much control you want. TBH creating a good controller either way is not particularly simple. Using a rigidbody will afford you some luxuries, but now you really don’t have much good reason to use Translate and would be better off with MovePosition. So… It’s basically one way or the other when you think about it.

Why is MovePosition better than changing velocity directly or using AddForce? Is it “cleaner”? More precise? Simpler?

Simpler. Adding force manually and taking ownership of velocity works fine but is more work.