Is it possible to make a fast reaction 2D jumping game with Unity's physics?
Heya,
I been working on a infinite running platformer game where the jumping mechanic is extremely tight, that is, certain chain jumps need to be executed at almost pixel precise moments and the whole jumping things needs to feel like people speed running Mario. For now I've worked with Rigidbodies and gravity and all the basic physic stuff, but as the game has progressed I've began to notice glitches here and there where the character would not jump though Debug.Log clearly states that a jump was registered in the correct boolean states. I'm not that good of a coder to code my own physics into the game right off the bat so I figured I'd continue with the Unity physics, but is this a doomed project?
Cheers
Answer by Andrii · May 25, 2016 at 04:19 PM
No it's not doomed. I'm working on a similar project and I've had similar problems. It looks to me that your problem is related to ground detection. I've had to try few different techniques to make it work properly for me. If you're making a platformer that is really precise, you should always know for sure if the player is standing on the ground. It will require you to learn a bit about how collisions work in Unity and a bit about raycasting if you haven't learned that already. Another thing that helped me was tweaking rigid body setting for the player (and other characters). Especially changing collision detection to continuous - this seems to make collision detection much more precise for that object.
I've actually tried alot of collision detection techniques (Raycasts, OnCollisionEnter, OnTriggerEnter to name the main ones). I guess what I'm asking is that will I run into physic glitches with the Colliders in the long run where the collision detection should work but for some reason, just for a frame, does not? Just a moment ago I had a collider that just didn't trigger OnTriggerEnter althought it was a copy pasted version of a collider that had been working up until that moment just fine. Another glitch I've ran into is that my character's BoxCollider sometimes registers a collision with an obstacle some 1 pixel before the actual collision, like the engine would be calculating that a collision will take place next frame, and jumping the gun.
I'm not experienced enough to say that Unity's physics engine is glitchy. So far I could overcome any problems I had with my platformer by changing the technique or tweaking some setting. I didn't have problems you're describing. I guess existing engine works in most cases but if you want to do something specific, you can write your own checks that would work better for your case. Some people ditch physics engine entirely and write their own system to manage movement of the objects, gravity, velocity in a way that suits their game better. It's probably O$$anonymous$$ to do it for some small 2D games. But I think that it's better to learn how to properly utilize existing system. There should be ways to work around the issues you're seeing.