How can I implement a "sticky" behavior in physics?

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

Hi there, I am trying to implement something like “sticky to walls” functionality, just like the kinematicbody 2d demo in platforms, but for everything… (walls, etc).

My game doesn’t have gravity, I want the player to jump and sticky at some places (moving or not).

Currently I am using kinematicbody for both, player and obstacles and when the player is_colliding() I set his motion (move()) to the get_collider_velocity().
It works sometimes, but the character motion is weird, his movement is not the same as the collider, sometimes it even “disconnect” from it.

What I am doing wrong? Can I get some directions?
Regards!

:bust_in_silhouette: Reply From: Ace-Dragon

For the first part, you might not be correctly adding the speed of the sticky object to the speed of the character when the player is moving him.

To start with, you can do a simple vector addition so that any player-controlled movement is synced with the surfaces (assuming both are Vector3 values, which then you can just do…
playerSpeed = playerMovement+colliderMovement).

For the second part, it might be that your character gets into a situation where it stops colliding with the surface. To fix this, you can assign the speed of the surface to a variable, use that variable as the value for the character’s movement, and only reset it to 0 if there’s no collision for more than N frames. Such as…

if collider == Null:
    timer += 1
else:
    timer = 0

if timer > 10:
    surfaceSpeed = Vector3(0,0,0)

Hope this gives some good direction.

Tks for the reply… I’ll give it a try!
Hugs

xupisco | 2016-05-13 20:57