Hello everyone! Welcome back to another instalment of the Blightmare Dev Blog! I hope you’re staying safe and sane out there as we make our way through these crazy times. Development on Blightmare has slowed a bit unfortunately as we all try to get a handle the new normal. But that’s enough of that for now. Today we’re going to be taking a look at moving platforms: how do they move, how do they work, and what are some of the complications?
A quick example of what moving platforms look like in Blightmare:
So how do we actually make a platform move? In Blightmare we use a pretty simple system that I like to think of as waypoints. In the editor, you can create a set of points that are aligned to the grid and the platform will follow the path at a constant speed. We have a few different configurations for the behaviour of a platform other than the speed and path. “Ping Pong” is the most common mode, which just goes back and forth along the path, optionally pausing at each end. Theres some cases where we want the platform to just go one way and stop, possibly snapping back to the start after a delay. Finally, there’s a setting to make the platform initially paused in its path until something is attached to it. Some of these modes can be seen in different mechanics. For example, the ground caterpillars don’t start moving until you jump on them, or the wall caterpillars go to the end of their path, pause, and then return to the start. Here’s what it looks like to build a silly platform path in the editor:
So now that we can make a platform move, how do we make it so that Blissa can actually ride on one? In general, this is pretty easy. If Blissa is “on” a platform, then she should move with the platform. What does it mean to be “on” a platform? We already have code that checks if Blissa is on the ground through the use of a short raycast – basically reach out in a direction and see if we touch something. This can tell us if there is a platform just below us and if there is, then we can go ahead and attach to it. Like many things, it’s a little bit more complicated than this in practice for moving platforms because both Blissa and the platform might be moving. This can cause several edge cases that we have to be careful about:
In Blightmare, we do a couple of things that help out with this problem. First off, we make sure the platforms don’t move too quickly which means that it’s much less likely to get into a bad state. We also use an “attach distance” – how close to the top of the platform you need to be before you’re on it – that is larger than our ground test distance so that the platform test is a little more conservative. Getting something that works in all cases is something that takes a bit of tuning, and it may eventually require something more complicated than what we have right now, but keeping things simple makes them easier to maintain and the platforms do everything we need.
Okay, so now that we know how to determine that we should be attached to a platform, how do we stick to it? That’s pretty easy actually – just add the platform’s movement into our own. In Blightmare, platforms are not physics-simulated objects, so getting the movement is a little different than other objects, but it turns out that this is helpful because the platforms will always move – they don’t stop because of collision – and therefore we can calculate the movement before doing the physics update where we need it. How this actually works is we store the offset – or distance away – from the platform that the attached object is. Then on update we add the object’s own movement to the offset and compute how the object would need to move to maintain the new offset. This is then fed through the collision system to see how far the object can actually move. Finally, we check to see if the final distance is too far from the platform, and detach the object if it is. This way, things will fall off platforms if there’s something in the way. There’s nothing special about Blissa in this system when it comes to attaching to platforms which can allow for some pretty interesting interactions. Check it out:
That’s about all there is to moving platforms in Blightmare, thanks for reading! If you’re enjoying these blogs, please tell your friends and be sure to wishlist Blightmare on Steam. Follow Plateau Games on Twitter to get the latest news about the blog and game. Keep those hands washed!