Handling collision from different directions

Okay, I’m trying to create a platform game that handles collisions a bit differently, hopefully I can explain this well…

Normally in a platform game, if you try to jump onto a platform and instead hit the left or right edge, you would simply fall straight down. I would like the player to actually latch onto the platform and move “through it”, gradually rising up over the next few frames until he is standing on top of the platform. If you’ve seen the old game Jumpman Jr., you may recognize this behavior.

I want to setup a CharacterController for the player, and obviously set up some kind of collider for the platforms. I’m thinking that once the player collides with the platform, I’ll set a flag to make him rise up and then once he’s not colliding anymore (because he’s on top), clear the flag. The problem is, how will he then stand on top of the platform without falling through?

Maybe not the best solution, but you could make the platform 2 seperate objects with the top a child of the sides. This might give you more control over what side was collided first - if I understand your problem correctly…

I thought about creating two separate objects at one point, but if you hit it from the side, you might collide with both at the same time. And I still have to handle the problem of being able to go through the top object initially and then coming to rest on it once the player rises up. I’m hoping to stay away from having to enable/disable colliders at run-time to solve this, cause that can get messy, especially if I have enemy characters walking around, etc.

any progress?

Not really yet. I’m experimenting with the collider functions included in the CharacterController component. You have to do a lot of stuff manually when using a CharacterController, so I think it’ll give me the flexibility I need. I’ll be notified when there’s a collision, and I can tell which side it’s colliding on. I should be able to use that information to determine how to respond. If the collision happens under the player, then he’s standing on the platform and I just keep him there, otherwise start raising him up. I just don’t want to get an up/down bouncing effect when he is on top of the platform because I apply gravity, and then he’s inside the platform again, and back and forth, back and forth.

cool, I have done this in flash. i will see if I can find that project on my backup, cause I’m sure you can use some of that code…

I think I may have the solution, and I’m working on testing it now. I basically turn on triggers for the platforms so the CharacterController will just pass right through (unless I do something to stop it). I’ll receive the OnTriggerStart, OnTriggerStay and OnTriggerExit notifications.

There’s basically three different scenarios at any given point: 1) the player is colliding with a platform and should be rising up, 2) the player is falling, and 3) the player is standing on a platform. I can use the trigger notifications to detect case #1. The other two I’ll differentiate by performing a raycast downward from the player for a short distance. If I detect a platform object there, it’s case #3 and I do nothing except allow left/right/jump controls to happen. Otherwise, it’s case #2 and I simply apply gravity.