Unity 5 Release Candidate 1
Unity 5 Release Candidate 1 came out today, and I upgraded to it.
It actually solved this weird bug I was dealing with, which is pretty awesome. The bug was with the boxes in the game. Every once in a while, if I dropped a box on top of another box, and then picked up the box again very quickly, it would still think it was in contact with the box below, and hence it wouldn’t drop.
Box and Detectors
I’m not using Unity’s default collision for my boxes, primarily because the physics system in the game is a bit more complex.
Each box has a detector on each face. A detector is square plane that is a trigger. Depending on which direction is “down” for the box, a detector will be turned on. This detector is used to determine if something has entered it or not, and hence the box knows whether it has hit something below it or not.
It seemed like the problem I was having was due to OnTriggerExit not registering properly. Honestly not sure why this was happening, but I was planning to write some kind of raycast system as a backup. However, the update to the newest version of unity seems to have fixed this problem.
Also finally implemented grid snapping today. It was actually a lot easier than I expected. I’d been meaning to do this for quite some time, but kept putting it off.
The main motivation was because sometimes the boxes would overlap with one another. I think this is just a Unity thing.
By setting up grid snapping when a box lands, it aligns it just right. The grid spacing I’m using right now is 0.1:
It’s a totally minor detail, but it’s something that bothered me tremendously. Also, sometimes players would get confused, thinking that the box got wedged in the wall intentionally.
Here’s the grid snapping coroutine code if you’re interested:
I put it in a coroutine because I only want to call it when the box lands on something below it. Otherwise, if you’re carrying the box, it’ll end up being very jittery because it will keep snapping.