Skip to main content
gamedev.net
🔒 Locked

Platformer physics

Started by Mephs 4 replies 2.5k views
Original Post
Mephs
Mephs
Assuming that you are making a 2d platformer with 3d elements, how would you handle collision with the 3d elements? I'm thinking that for the main character on a normal 2d element of the landscape I will simply use line swept circle tests against the lines of the 2D polygons, but I'm a little stumped when it comes to how to integrate 3d objects, especially when they may be animated. Assume, if you will, that we have a ball on a chain that swings round in 3D, but we want the player to be able to jump around on the top of the 2d projection of the ball, and be damaged if they hit the side or underneath. I'm wondering if it would be best to code a system to deal with arbitrary 3d objects, or if it would be best to do something like having an editor to simplify the geometry into blocks, bearing in mind we want player movement to be smooth and not stuttered by every tiny bit of geometry that might be in the way, such as the chain part of the ball and chain. This might be quite straightforward with static objects, but another level of complexity is added with objects like the ball and chain that move around, the simplified geometry must know how to animate in the same manner as their parent. Perhaps the best approach is a plugin for your 3d modeller of choice, or an in game editor that allows you to specify what parts of the geometry are to be treated as platforms, damage dealing entities and geometry that should not affect the player... I suppose in that way we know the geometry will animate correctly, we can model a platform into the ball and set it as a platform and we can make the ball itself a damage dealing object... then I suppose we just use the line swept circle test to check for collision. So how would you approach this problem? Do you have any better ideas? Cheers, Steve
Numsgil
Numsgil
This isn't a perfect solution, just a brain storm to get you thinking ;)

Sounds to me like you should project your 3D objects' vertices onto the plane the player is in. Find the smallest bounding circle that encompasses all the projected points of an object. Perform a swept circle to swept circle using the players previous and current position, and the last projected bounding circle and the new projected bounding circle.

The new and old bounding circles for the projected points might actually vary in size, so you'd want to change the swept circle algorithm to account for a radius dependant on time, and then LERP between the two known radiuses.

That's probably overkill for your purposes though. Platformers tend not to need uber-nice collision detection.
[size=2]Darwinbots - [size=2]Artificial life simulation
JBourrie
JBourrie
Quote:
Original post by Numsgil
That's probably overkill for your purposes though. Platformers tend not to need uber-nice collision detection.

Au contraire, platformers live and die by their collision detection. Platfomers are all about navigating a complex environment with precision, wonky collision detection makes this more difficult.

That being said, the changing size of the ball and chain projection (since it's in 3D space) isn't the only problem. Even with that fixed, why is the player able to jump within the plane and land on an object that is outside of that plane? How will this be displayed on screen? Will the player jump out of the plane to land on the ball?

It seems that the collision detection is the easy part. I can't think of one good way to actually present this visually to the player.

Mephs
Mephs
Sorry, I should have been more clear, but I didn't really intend the player to leave their movement plane, I just want to use some 3d objects to give parts of the scene more depth and to demonstrate on my portfolio that I can handle 2d and 3d programming.

To that end, the ball would be swinging in a half circle from left to right rather than into and out of the screen. Each frame I would project the lines formed by the polygons of the 3d object onto the movement plane and use those for collision detection... at least I think that would work best.

I just repeat my original idea because I'm not sure if this advice has been presented with the thought that my 3d objects will move out of the normal plane of movement, though perhaps it is still not the most appropriate method?

Thanks for the thoughts so far though, they are much appreciated and it has heped me to clarify my meaning!

Cheers,

Steve
OrangyTang
OrangyTang
Quote:
Original post by Mephs
or if it would be best to do something like having an editor to simplify the geometry into blocks, bearing in mind we want player movement to be smooth and not stuttered by every tiny bit of geometry that might be in the way, such as the chain part of the ball and chain.

I'd go with this way. Just have some simple method of attaching 2d collision geometry to your 3d animations and use that instead of trying to deal with collisions again the mesh directly.

Mainly I think this is a good idea because you're decoupling the graphics from the gameplay/collision. You really don't want an artist suddenly changing all the gameplay because they've decided to make the surfaces wobbly or something.

Dealing with moving objects and their collision geometry is tricker. I'd probably either have a static ball mesh + collision and make it move/swing in code and generate the chain procedurally (so you keep track of the geometry position manually). Or for a more generic system you'd probably need skeletenal animation and attach your collision geometry to the bones so it can be updated with the mesh.
grhodes_at_work
grhodes_at_work
Did anyone play the first two Oddworld games, the ones that were on PC and Playstation (1)? These had an interesting visual mix of 2D and 3D elements. They were 2D platformer games, but with the playable bits over a 3D background that looked quite deep. And when transitioning from one area to another, they animated the camera in a way that showed movement through the 3D world, but seamlessly ending at a point that showed the playing plane. It was done very, very well. All gameplay was purely 2D, but it did highlight the 3D world.

There are playable demos of these games available at the link below. Not sure if the scene-to-scene transition is shown in the demos, but at least the environments (some of them) are there.

Oddworld PC Game Demos

[Edited by - grhodes_at_work on September 12, 2006 10:00:48 AM]
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.