Metroidvania "Wall-Sticking Movement" Mechanics? [2D Platform/GDScript/Kinematic]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Corruptinator
:warning: Old Version Published before Godot 3 was released.

This might be vague to ask but, does anybody know how to make a 2D kinematic body stick to the wall and move in a direction depending if the wall/floor is Horizontal, Vertical, or Angled; similar to how the the SpiderBall Ability or the Geemer Mechanics work?

I can only think of two possible pseudo-code theories on how this works…

[Ideal/effective method]

  1. When it makes contact with a platform or surface it detects which angle it is touching upon, next it would tell the gravity to make the object move towards the contact coordinates that the collision detection is saying from its x and y axis.

[Easier/lazy method]
2) Simple, using navigation points to tell the object which way to go.

I prefer method 1 better, but I’d like to hear what works best to make the wall-stick movement mechanic works code-wise.

You may want relative movement, is just matter of checking collision normal to adjust it.

Also, if you think the lazy method can be done faster for you, go for it, you can change it later for a better one :wink:

eons | 2016-10-13 14:59

:bust_in_silhouette: Reply From: avencherus

Well it sounds like you would need a bit more information, because I assume you’ll have situations where you will have contact with both the floor and a wall in every corner. If not that probem, then a very rapid jittering, frame by frame, between the two colliders you have for a wall and a floor.

So checking the collision bodies, you could see what their rotations are relative to the world. That will be able to answer their orientations. Then you have to probably tune and compare with the character’s velocity, or look at what the movement input is to decide which surface you want to choose to “stick” to.