![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | AshTheKindra |
So you know how in your typical 2D platformers like Super Meat Boy or Mario when you’re running to either the left or right and then you jump, your momentum carries over to your jump, and when you let go of the directional buttons, you still move to the right or left because of that momentum? So I’m making a 2D platformer and I’m trying to refine the controls. I have most of the controls work the way I want to. The jump even works right, when I run and jump while holding down the left or right button, my character goes to the left or right. However, if I run and jump and let go of any of the direction keys, my character stops in mid air and drops like a brick because momentum didn’t carry over to my jump. I have tried to put acceleration and friction into the jumping values, but that doesn’t seem to work The coed for jumping is below, any help would be appreciated.
func _physics_process(delta: float) -> void:
_get_input()
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP)
if Input.is_action_just_pressed("jump"):
if is_on_floor() or nextToWall():
velocity.y = jump_speed
if not is_on_floor() and nextToRightWall():
velocity.x -= wallJump + jumpWall
if not is_on_floor() and nextToLeftWall():
velocity.x += wallJump + jumpWall
if nextToWall():
$AnimatedSprite.play("Wall Slide")
if nextToWall() and velocity.y > 30:
velocity.y = 30
$AnimatedSprite.play("Wall Slide")
if not is_on_floor() and not nextToWall():
if velocity.y < 0:
$AnimatedSprite.play("Jump")
if velocity.y > 0:
$AnimatedSprite.play("Fall")
if Input.is_action_just_released("jump"):
if sign(velocity.y) != 1:
velocity.y = 0