Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody2D
- @export var speed : float = 200.0
- @export var jump_Velocity : float = -200.0
- @export var double_jump_Velocity : float = -100.0
- # Get the gravity from the project settings to be synced with RigidBody nodes.
- var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
- var has_double_jumped : bool = false
- func _physics_process(delta):
- # Add the gravity.
- if not is_on_floor():
- velocity.y += gravity * delta
- else:
- has_double_jumped = false
- # Handle Jump.
- if Input.is_action_just_pressed("jump"):
- if is_on_floor():
- #Normal jump from ground
- velocity.y = jump_Velocity
- elif not has_double_jumped:
- #double jump in air.
- velocity.y = double_jump_Velocity
- has_double_jumped = true
- # Get the input direction and handle the movement/deceleration.
- var direction = Input.get_axis("left", "right")
- if direction:
- velocity.x = direction * speed
- else:
- velocity.x = move_toward(velocity.x, 0, speed)
- move_and_slide()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement