Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ddarkmoto | |
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
#add force
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