What's the best way to move a platform horizontally and vertically?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JayH


Hi, I’ve been tinkering with moving platforms horizontally and vertically for a platform game. I’m struggling though, as I’m not sure what people typically do.

I wish to re-use the sprite and script within the game, so I considered that it should move freely, but only reverse direction when it reaches an invisible marker sprite that I add at one end and the other.

But that raised other questions, “How do you detect the collision to reverse?”, “Should the moving platform be a KinamaticBody2D, or something else?”, “Do I use layers to prevent the player from colliding with the invisible marker?”, if so how?

There’s so few examples of this online and none seem applicable, what would you guys suggest?


Please note, this is for a pixel platform game, so lerps etc probably wouldn’t move so well.

You can put an AnimationPlayer component on it, create a new animation.

THIS will enable you to see keys icons on everywhere for everything in settings. For example, you want to move the position A to B, so you will need a start point and and ending point. Click on the key icon near the position settings, and this will create a track for animation of the position with the key on starting point. Move the platform and then choose an ending point clicking in the track timeline, then click on the key icon button again. Voilá, you will have an animation.

Plus, you even don’t need a line of code to animate this. You can go to AnimationPlayer settings and click on “A” (Autoplay on load) and also click on “Animation looping” button.

When you play this level will perform the move automatically.

Alex Pires | 2019-02-24 17:58