how to make rigidbody2d stick to wall

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

I’m quite new to Godot engine and new to game development in general.

So what i’m trying to do is to make my rigidbody character stick to the wall
but i couldnt manage to do it properly i’ve tried changing its mode to static or
changing sleeping state to true when touching a wall these worked but when my rigidbody touches to the wall with high velocity it sometimes stucks inside of the wall or it bounces and freezes in mid air
basicaly what im trying to do is i have a sticky rigidbody ball and i want it stick to a surface it touches

If you want the ball to stick to any wall, you can check for wall collision in the code.

Check for whether the ball is colliding with a wall object via a body_entered signal. When this signal is fired off, use the body parameter of body_enteted and the name attribute of body to determine whether the object is a wall. Next, assign the position of the collision point to be the current position of the ball, and turn off any other movement code. When you want to move the ball, allow the ball to move again, and reinstate the movement code.

Ertain | 2018-11-08 19:24

:bust_in_silhouette: Reply From: MarkProDev

I’m new too but maybe I can help. Because rigidbody responds to physics you’ll probably need to make its mass zero and friction high and use add_force to “press” the body toward the surface.
Alternatively, depending upon the complexity of the shape you could convert it to a KinematicBody and add a raycast in each direction you want to stick. Then when you detect an imminent collision, manually set the position of the body to adhere to the surface.

I’ve not tried this through altering the object’s physics. I’ve only tried to freeze it when it touches a wall but this might actually work thank you Mark.
I was searching about continous collision detection to make it work
if altering physics work you would probably be my savior

Yoruichill | 2018-11-08 20:19