Sphere to Line Response

This topic is 4872 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey All, Working on a platformer game. World collision works like this: the Scene Manager has a list of line segments that define collidable platforms. If an object is of the type that does collide with platforms, it calls into the scene manager and gets the list. Here is what I have so far: 1) Object gets list of line segs For each of the line segments 2) Object tests if it's radius (object use spheres for collision bodies) is less than the distance from itself to the closest point of the line. 3) if it is, I move the object in the direction of the line's normal, by a distance of object's radius minus the distance to the closest point on the line. The works great so far. Problem is when jumping up from under a platform/line, the moment you touch it, you get shot up to the top. It should instead not do anything until you are moving towards the normal. How would I calculate that instance? I belive it's something like the dot prod of the lines normal and the objects forward vector; if it's neg it means it's on one side, if the result is pos it means its on the other. Not sure though. Edit: Also, I foresee a problem with this, in that what happens when an object doesn't quite make it over the line (picture the player jumping, and just his head goes over the platform before gravity over takes his upward momentum). In this case, as soon as he starts going down again he will pop up to the plat. Seems like i will also need to check that vector from the object to the line is also on the same side of the normal or something... direction please [wink] And sample code would be great! And if u have any suggestions about how i'm doing any of the other stuff, feel free to comment. Thanks, Matt

Share on other sites
You could always track the height at the origin of the jump, and if it is less than the height of the platform, then ignore any collision with it. If the character doesn't jump high enough, then it just falls back to its original surface.

Share on other sites
Yeah, I thought about doing something that, but I'd like to keep the collision response as generic as possible so that, for example, the same code would work for roofs that have normals pointing straight down.

Thanks!
Matt

Share on other sites
Just to be clear on the behavior you're looking for... If you're under a platform and then jump, you don't want the player to hit the underside of the platform and fall back down, but rather keep going up past the platform and then land on it on the way back down. In other words, even though it's 2d there's a bit of a 3d aspect in that the player jumps up 'past' the platform and then lands on it.

Or are you just looking for straightforward collision response where collision with any obstacle in any direction has the expected effect?

Share on other sites
Yeah you got it in the 1st paragraph. Think like mario bros, or contra. It's not really a '3D aspect'; we just ignore logic for the sake of playability :)

I actually made a fix already. I store an extra piece of data in the line seg objects saying if it is a floor or not. If it is, than I do some 'make sure its this... make sure it's not that... etc' checks before preforming collision. Else, do it correctly.

Works fine, but I'd still like to figure out something a little more generic.

Matt

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 11
• 29
• 15
• 41
• Forum Statistics

• Total Topics
634838
• Total Posts
3019568
×