Sprite keeps on being stuck on the wall

Attention Topic was automatically imported from the old Question2Answer platform.
Old Version Published before Godot 3 was released.

Hi everyone. It seems that every time I press the left and right movement button, the sprite keeps on sticking on the edge of a staticbody2d for as long I press them. Thoughts? Thank you.

Add more details on how are you moving the rigid body, if you keep adding impulse/forces and has a high friction, is normal for it to get stuck (like in real physics).

eons | 2017-03-14 20:45

Can you post the movement code?

keke | 2017-03-14 23:19

Hi Keke and eons.

Here’s the code for my movement
charmovement script

``````const DIRECTION = {
ZERO = Vector2(0,0),
LEFT = Vector2(-1, 0),
RIGHT = Vector2(1, 0),
UP = Vector2(0, -1),
DOWN = Vector2(0, 1)
}

func _integrate_forces(state):
#final force
var final_force = Vector2()

directional_force = DIRECTION.ZERO

apply_force(state)

final_force =state.get_linear_velocity() + (directional_force * acceleration)

#prevent from exceeding top speed
if (final_force.x > top_move_speed):
final_force.x = top_move_speed
elif (final_force.x < -top_move_speed):
final_force.x = -top_move_speed

if (final_force.y > top_jump_speed):
final_force.y = top_jump_speed
elif (final_force.y < -top_jump_speed):
final_force.y = -top_jump_speed

state.set_linear_velocity(final_force)
``````

Code for the player script
if (Input.is_action_pressed(“ui_left”)):
directional_force += DIRECTION.LEFT
direction = “left”
print(directional_force)
if (Input.is_action_pressed(“ui_right”)):
directional_force += DIRECTION.RIGHT
direction = “right”
print(directional_force)
if (Input.is_action_pressed(“jump”) && jump_time < TOP_JUMP_TIME && can_jump ):
directional_force += DIRECTION.UP
jump_time += state.get_step()
else:
can_jump = false

ddarkmoto | 2017-03-15 13:57

Try using a round collision shape, rather than a capsule. The flat edges basically have friction, hence why you’re sticking. With a circular shape, you should be ok.

Tried it with different shapes and it didn’t work but thanks for the suggestion. Appreciate it

ddarkmoto | 2017-03-15 13:40

Have you set the Friction option to zero?

In my case, RigidBody2D objects will stick on collision fields, like ground…

Yes sir. I tried and it didn’t work.

ddarkmoto | 2017-03-17 13:30

2. unrelated use `clamp ( float val, float min, float max )` instead of the if’s