- Home /
Simple Movement Game: Physics vs Manual Collision Detection?
Hi,
I am trying to develop a game with very simple movement of a character - run around with consistent velocity or stop moving, go up slopes, cannot run into walls / characters / objects. As far as I know, I have two options to implement this:
Character with rigidbody (isKinematic set to false): use the physics system, have to apply force to move things. Seems kinda hard to remove all bouncing, friction etc. Also, using physics seems to be over the top for this relatively simple movement.
Character with rigidbody (isKinematic set to true): detect collision by attaching colliders to other objects, then compute where to stop the character (potentially using Physics.ComputePenetration?). Moving by rigidbody.MovePosition or setting transform.position seems easy compared to adding force, but collision handling has to be done manually and especially slopes seem kind of challenging.
Which version would be best for this kind of movement? Thanks for your help
Answer by unity_ek98vnTRplGj8Q · Jan 03, 2020 at 08:52 PM
Disclaimer: not super confident that this answer is 100% correct
May I recommend a 3rd option? Check out the Unity CharacterController script: https://docs.unity3d.com/ScriptReference/CharacterController.html. It acts like your second option, but handles a lot of the harder stuff that you will eventually run in to by just using a rigidbody. It is excellent for creating quick and easy character movement, then if later down the road you decide its too restrictive you can try writing your own character controller using a rigidbody, like you talk about in you second approach.
If this approach doesn't work out for you then, yes, in general movement scripts are made using the second option, though I've never done this myself. I think that Rigidbody.MovePosition may detect collisions for you to prevent you walking through walls, but not sure
Answer by logicandchaos · Jan 04, 2020 at 05:27 AM
I'm not sure in my new game I'm using the unity physics, but implementing the gravity myself for more control. It's a 2d side scroller. But you have to move objects with the rb in order for collisions to work properly, however you can also handle collisions on your own using vector distance, raycast, overlapCircle and others. Using other options could be more efficient than unity collisions as well.. but depends on the situation.