Character stucks on walls - RigidBody2D

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

Hi!
So, i made character movement in Rigidbody2d with…

func move(speed, acc, delta): 
current_speed.x = lerp(current_speed.x , speed, acc * delta)
set_linear_velocity(Vector2(current_speed.x,get_linear_velocity().y))


func _fixed_process(delta):
if left:
	move(-move_spd, acceleration, delta)

And when ever i jump(and ceep direction button down) and hit the wall, character sticks to the wall and doesnt fall down until i release that direction button (force)…
How can i make code so that doesnt happen?
Btw, the tile set consists of just sprite+collision shape
enter image description here

That could be because you are setting linear velocity, try with impulses instead.

Or better, look at the Platformer demo to see how it uses the custom integrator (_integrate_forces) to manipulate the forces over the body.

eons | 2017-01-02 14:21

I have tried few times that, didnt get anything working out of it so far, that code doesnt make sense to me …

Serenade | 2017-01-02 22:49

:bust_in_silhouette: Reply From: avencherus

It’s hard to say precisely with only that much information.

It would be worth examining the collision shapes and conditions you use before applying any velocity. You didn’t mention the type of shape being used, sometimes rectangles catch on the corners in strange places.

One common technique for this style of 2D is to use a small ray cast at the player’s feet to detect floor contact (making sure to add the player to it’s exclusion list and fine tune it’s length for desired effect).

When there are issues with walls or slopes, then you may need additional logic that checks against specific collision objects in the world. Such as making decisions about velocity or player’s control when they press against a wall. If you’re not getting reliable contact information about walls, you may also want to cast rays forward to see if there is wall contact.

I might be wrong, but the code you’ve listed reminds me of Andreas’ G-Bot tutorial. If you’re using his example, I would look at some of his other logic regarding walls. In his source files the character is designed to cling to walls in order to climb up them using jumps.

No no, collision shape doesnt change a thing, my character already has round edges, so it doesnt stuck while moving on X level… but the thing is that it ceeps sticking to walls (above ground) while i ceep the movement towards it going.
And yeah, it is, but in his code, character doesnt stick to walls when hit them in air… : / and from tutorial that i learned (i tested it on my godot) it did not get stuck… i dont know. my code knoladge is too low to make anything out of those raycasts as well…

Serenade | 2017-01-02 22:47

They’re worth learning. You have to test what will happen if you halt the velocity into a wall when there is collision. I suspect it’s getting stuck because of the friction.

avencherus | 2017-01-03 00:30

Thank you very much. I had the same problem and the friction of the rigid body was the solution.

heidebeere | 2018-01-03 11:32

:bust_in_silhouette: Reply From: fdfd

This is probably way too late of an answer, but to fix this you need to add a custom physics material to the RigidBody2D and set friction to 0.