I’m currently working on a Super Mario Bros remake, and it’s going well aside from a few collision issues.
I’m using Raycasts to determine the situations to apply gravity. In this specific issue, I am spawning a mushroom item, which is a cube with a texture, has a box collider, mesh renderer, a rigidbody, and the script to handle it all. I am using it as a trigger, so a player can pass through it which I think is smoother than grabbing it when they touch the edge of it.
Current mushroom item script: #pragma strict// =========================================================== - Pastebin.com
The way the gravity works, is:
- Mushroom has a rigid body, constrained on all axes except X (left/right or ‘horizontal’)
- If the Mushroom doesn’t have an object within 0.6 of it’s bottom, I assume it is floating and I should apply gravity to it.
- Unconstrain Y axis so rigidbody can work it’s magic
The problem is, it doesn’t check if 4 points are all in the air, it only checks for 1 point of the box, which I assume is the very center vertice. I’m wondering if there’s a way to check if the entire bottom of the box (or the 4 bottom vertices), if they are all floating.
So the real issue is that it is triggering the OnTrigger method when the corner of the mushroom catches on the floor it is going to fall off of. This wouldn’t be much of an issue, except I am also checking if the mushroom hits a wall so it can flip directions (If you ever played any mario game, you would know what I mean).
Edit: I’m open to completely rewriting this system too, so don’t be afraid to make a better suggestion than what I have.