Path Follow Platforms
We saw in the Moving Platforms post that is very easy to achieve Moving Platforms in Godot Engine, but as mentioned at the end it is kinda annoying to design their movement using solely the AnimationPlayer. So let’s talk about how to design all sorts of movement using a design-friendly approach, again with no code required.
Path Follow Platforms
Yes, if you already know the PathFollow2D node you can see where we are going already, but keep reading because there’s a small trick to make this work with KinematicBody2Ds.
Let’s start from the beginning, we are going to create a scene with a Path2D node as root. This is the core of our platform movement designing toolkit. Through this node, we can create and design paths that can even contain curves!
The next step is to add a PathFollow2D node as a child of the Path2D. As said in the documentation a PathFollow2D is:
[…] useful for making other nodes follow a path, without coding the movement pattern. For that, the nodes must be children of this node. The descendant nodes will then move accordingly when setting an offset in this node.
Quite straight forward, right? Before we add our MovingPlatform as a child of the PathFollow2D let’s add an AnimationPlayer as a child of the Path2DFollow and remove the one in the MovingPlatform scene. This is how the scene structure looks like by now:
The way we can ensure that no matter the length of the Curve2D we create the PathFollow2D always runs through every point is by animating the Path2DFollow > Unit Offset property. This is a unitary version of the Offset property, meaning we can offset the Path2DFollow position in the curve using a value that always goes from 0.0
to 1.0
, or rather, from 0%
to 100%
. So we can create an animation with a single track that interpolates this property along its duration. Don’t forget to change the Path2DFollow/AnimationPlayer > Process Mode to “Physics”.
Also, if you want the platform to always be moving, remember to toggle the Autoplay option on the animation to ensure it’s going to play when we load the game. Otherwise, you have to use some kind of trigger to make it play in the middle of the game, like an Area2D to make the platform move when the player is close.
Now if you try this out…it won’t work! Haha, gotcha. You thought there weren’t any secrets here, right? This is what happens if you try to test this setup as it is:
For some reason, the actual collision shape doesn’t get its position updated using this approach, which is quite unfortunate. But here goes the fix.
Fixing the collision
If we simply add a RemoteTransform2D as a child of the PathFollow2D instead of the MovingPlatform we can use it to point to the MovingPlatform, that should now be a child of the Path2D.
And with that, we fixed the issue! No, I don’t know how, I don’t know why it just works, there are some cases where we just need to accept that we don’t understand certain issues nor their solutions. Like why a wooden spoon prevents the pasta from boiling over, we just accept that it does and life goes on.
Designing the movement
Now that we have our platform movement designing toolkit in place we just need to create new paths and see the magic happening. There are some notes to keep in mind tho:
- Make sure to always create a new Curve2D otherwise you’re going to mess with shared resources
- You can mark the PathFollowPlatform as an Editable Children and play with the animation’s duration to speed up or slow down the platform movement.
Files
Get Gamedev Experiments
Gamedev Experiments
A collection of gamedev experiments cut down to small digestible projects
Status | In development |
Category | Assets |
Author | Pigdev |
Genre | Platformer |
Tags | Creative, flat-shading, Game Design, godot-engine, Open Source, secrets, sourcecode |
More posts
- Selection BoxAug 06, 2020
- Selectable ObjectsJul 30, 2020
- Jump with SnapJul 24, 2020
- Jump and Fall Through PlatformsJul 23, 2020
- Moving PlatformsJul 10, 2020
- Tilting on SlopesJul 01, 2020
- Slope MovementJun 27, 2020
Comments
Log in with itch.io to leave a comment.
i created the animation but when i debug, it doesnt play (im sorry if i write bad, i dont speek english very well)
Turn on "Autoplay" on the animation's editor
whats that?
It's an option...in the animation editor you can set an animation to be Autoplay.
Please, do take the time to learn the Godot Engine editor.