Advertisement
ZeeLinuxGuy

Godot Player code.

Aug 11th, 2023
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.99 KB | Gaming | 0 0
  1. extends CharacterBody2D
  2.  
  3.  
  4. @export var speed : float =  200.0
  5. @export var jump_Velocity : float = -200.0
  6. @export var double_jump_Velocity : float = -100.0
  7.  
  8. # Get the gravity from the project settings to be synced with RigidBody nodes.
  9. var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
  10. var has_double_jumped : bool = false
  11.  
  12. func _physics_process(delta):
  13.     # Add the gravity.
  14.     if not is_on_floor():
  15.         velocity.y += gravity * delta
  16.     else:
  17.         has_double_jumped = false
  18.        
  19.     # Handle Jump.
  20.     if Input.is_action_just_pressed("jump"):
  21.         if is_on_floor():
  22.             #Normal jump from ground
  23.             velocity.y = jump_Velocity
  24.            
  25.     elif not has_double_jumped:
  26.     #double jump in air.
  27.         velocity.y = double_jump_Velocity
  28.         has_double_jumped = true
  29.  
  30.     # Get the input direction and handle the movement/deceleration.
  31.    
  32.     var direction = Input.get_axis("left", "right")
  33.     if direction:
  34.         velocity.x = direction * speed
  35.     else:
  36.         velocity.x = move_toward(velocity.x, 0, speed)
  37.  
  38.     move_and_slide()
Tags: programming
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement