Hello. New to the Unity engine. Hope this is the right place to post.
I’m making a custom character controller for a game that has dynamic gravity. So I got a capsule mesh and a capsule collider. Good start.
Now the first step is to make the character fall when he’s not tangent to the ground, and not fall when he is standing on the ground. I can think of two potential ways to do this. 1) Apply constant downward force and trust Unity’s physics to prevent him from falling through the ground. 2) Use raycasting to determine when he comes in contact with the ground and then stop applying a downward movement, in order to keep him floating some minuscule distance above actually touching the ground.
What’s the more kosher way to do this? Which is more reliable?
Okay. I think I was overthinking this. I didn’t realize how much Unity’s physics engine gave me.
So the current plan is to have a rotation-constrained rigid body collider for a player character. Gravity is applied (either through Unity’s gravity or my own scripted gravity). Then, on every frame, I shoot a real short ray out my feet to determine whether I’m currently grounded.
The physics engine makes me grounded; the ray tells me if I am grounded.