0 votes

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 iscolliding() I set his motion (move()) to the getcollider_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!

in Engine by (12 points)

1 Answer

0 votes

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.

by (138 points)

Tks for the reply... I'll give it a try!
Hugs

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.