- Home /
Physics-free collision problems
I could really use advice on how to handle collision detection when making polished platformer-style controls within Unity. Normally I prefer to figure things out on my own but I'm at my wit's end.
I have implemented a physics-free movement, using a non-Kinematic RigidBody with a cylinder-shaped mesh collider parented to it. As far as I know I cannot use the Character Controller as a capsule-shaped collision bound leads to very unsatisfying handling on the edge of platforms, ramps, etc., so it's unacceptable. I need it to be a cylinder.
I handle all movement logic in my own code, and at the end I move the object using rigidbody.MovePosition( pos ). I set rigidbody.velocity to 0 every FixedUpdate as I don't want any physics simulation to happen. After this, the object gets pushed out of whatever terrain it may intersect. I detect the ground by testing the normal in OnCollisionStay.
This seems to work OK for very low player speeds. However, when the object moves even a little fast, it clips through walls. Setting "Interpolate" and "Continuous Dynamic" on the RigidBody seem to do nothing. It looks like rigidBody.MovePosition either does not honor interpolated collisions, or the Unity programmers chickened out of coding mesh collider vs. mesh collider interpolation. Adding a capsule collider to my collision bounds doesn't seem to help, though.
Common practice seems to be setting rigidbody's velocity or applying force to it, and try to trick Unity's physics simulation into handling the collision. This seems to fix the wall problem but leads to other problems. There seems to be a one-frame lag because applying velocity to rigidbody only affects the [i]next[/i] frame, not the [i]current[/i] one. It also seems to affect the way collisions are detected in a way that causes glitchy, erratic behavior when interacting with colliders besides the terrain, likely attributable to the lag.
As a last-ditch effort I would jettison Unity's pushout code and try to do it myself by feeling around using RigidBody.SweepTest (which I could foresee causing performance problems). However, frustratingly, Unity's documentation states that it only works with primitive collision types.
It really looks like Unity is intended for physics-based games only, but not every designer wants their game to be a laggy, slippery kludge-fest. I need "fake" physics. I really think/hope this problem must have been solved simply, dozens of times, and I just haven't been doing the right Google searches.
Any help with this would be vastly appreciated. I'm this close to the ironic, degrading task of manually coding mesh vs. mesh intersect detection for a game engine I paid thousands for.
Have you tried lowering the $$anonymous$$inimum Penetration for Penalty in Edit -> Physics?
That doesn't seem to have any effect, but thanks for your response.
Your answer
Follow this Question
Related Questions
NavMesh Collision Detection? 0 Answers
Collision Dection on Tigger Enter 1 Answer
Last collision 1 Answer
How to detect collision on only one side of an object? [C#] 4 Answers
Why does my OnCollisionEnter2D not work? 3 Answers