SSP Prototype - Moving Platforms

posted in Beals Software
Published January 28, 2011
Advertisement

DbPrototypes_SSP_28Jan11.PNG



After a lengthy refactoring of my collision manager, I've implemented moving platforms in the Side Scrolling Platform. This screenshot requires less explanation as I've removed the debug text and rendered the actor's names.

- Platform A is moving horizontally from {256,560} to {512,560} at a speed of 32.
- Platform B is moving horizontally from {128,460} to {512,460} at a speed of 64.
- Platform C is moving vertically from {128,160} to {128,560} at a speed of 64.

I had to rewrite my collision manager because my response code hard-coded directly in the test function (but I still had response callbacks...yea, I don't really know what I was thinking.) After refactoring, I now have an "ActorTerrainCollision" response callback, in which I respond to collision between an actor and a tile, and an "ActorActorCollision" response callback, in which I respond to collisions between two actors.

To implement moving platforms, I've added a property to my PlatformerActor class named 'Link.' Whenever an actor (Actor1) lands on the top of another actor (Actor2), I set Actor1's Link to Actor2. Then, when updating, I apply the Velocity associated with Actor1.Link to Actor1's position. Thus, as Actor1.Link moves, so does Actor1.

[As I was typing this, I realized a small bug. The only time I clear an Actor's Link is if they jump, which on CharacterActor's can do (CharacterActor is derived from PlatformerActor. PlatformerActor is used for anything from crates to platforms to people, whereas CharacterActor is used for only people.) So, after walking off of a platform, I continue move along with my link.]
Previous Entry SSP Prototype
Next Entry Editor
0 likes 4 comments

Comments

Aardvajk
Moving platforms are always a pain to get right. Glad you're making progress.

I was thinking a while ago about having a system where every single object was always linked to some kind of parent and had its own transform updated by its parent every frame, then for objects not on moving platforms, I could just set their parent to the world, which just had a null transform.

I think that may be a solution that allows for stacking objects on moving platforms etc but it's just a theory, not actually implemented. One thing puzzling me is the order to update all the transforms. Maybe you would have to build some kind of tree then iterate down from the root (the world), applying the transform to each leaf.

If it's any consolation, it is pretty much accepted as impossible to get moving platforms working right in Box2D so they won't be putting an appearance into Squishy.
January 28, 2011 02:18 PM
Programmer16
Thanks Aardvajk!

That's pretty much how I have things setup, with the exception of linking it to the world. Originally I had platforms link to the object(s) touching it, but I've reversed it so that an object stores a link to the object it is touching. This allows me to have two objects standing on the same object or objects standing on top of each other.

The order of updating the transforms is the hard part. For example, with my current setup, it all depends on who was added to the list first. I just have a function that updates each object's velocity, then moves them, then moves them by their link's velocity. So, for example we have to boxes on top of each other, Box1 and Box2 (Box1 being added first and being on bottom.) When Box1 moves, if Box2 is too close to the edge opposite the direction that Box1 moved, it'll fall off.

The nice thing about this is that I can use it for a lot of other things too. One idea I thought of was like a spaceship flying through space or boats, etc. Basically, I'm trying to design it to be able to do away with the old tile map.

I thought I had read somewhere that moving platforms could be implemented in Box2D via prismatic joints. Hopefully someone figures it out, as I would see that as a major negative to the library (not that moving platforms are a huge requirement, but most everyone wants to have moving platforms in their games.)

Thanks again for the comment!
January 28, 2011 05:47 PM
Aardvajk
[quote name='Programmer16' timestamp='1296236829']
I thought I had read somewhere that moving platforms could be implemented in Box2D via prismatic joints. [/quote]

Yeah, you can physically make moving platforms. It's just not possible to make objects on the platforms behave correctly. Downside of a realistic physics simulation I guess.

[quote name='Programmer16' timestamp='1296236829']
Thanks again for the comment!
[/quote]

Hey, no problem. I always read your posts, I just haven't commented for a while.
January 28, 2011 08:40 PM
Programmer16
[quote name='Aardvajk' timestamp='1296247239']
Yeah, you can physically make moving platforms. It's just not possible to make objects on the platforms behave correctly. Downside of a realistic physics simulation I guess.
[/quote]
Ah, I see.

[quote name='Aardvajk' timestamp='1296247239']
Hey, no problem. I always read your posts, I just haven't commented for a while.
[/quote]

Heh, I'm the same way.
January 29, 2011 07:04 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement