diff --git a/scripts/player.gd b/scripts/player.gd index 4798388..165a0e6 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -5,6 +5,7 @@ const SPEED = 300.0 const JUMP_VELOCITY = -400.0 #add a variable for momentum...t.w. @export var acceleration:int = 8 +@export var hard_gravity:float =1.5 var direction:float = 0 @export var BUMP_POWER = 100 enum FaceDirection{LEFT, RIGHT} @@ -18,6 +19,10 @@ var pushEnabled:bool = false @onready var jump_buffer_timer: Timer = $JumpBufferTimer +#For State Machine.............t.w. +enum State{IDLE, RUNNING, JUMP, FALLING} +var current_state:State = State.IDLE + func _physics_process(delta): # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. @@ -71,12 +76,20 @@ func handle_movement(_delta)->void: else: velocity.x = move_toward(velocity.x, SPEED * direction, acceleration) - if not is_on_floor(): + if current_state == State.JUMP: + #apply normal velocity velocity += get_gravity() * _delta + if velocity.y>0: + current_state = State.FALLING + else: + #apply hard gravity, character falling + velocity += get_gravity() * hard_gravity * _delta #add a buffer timer to the jump velocity............t.w. if is_on_floor() && jump_buffer_timer.time_left >0: velocity.y = JUMP_VELOCITY + #change state...........t.w. + current_state = State.JUMP jump_buffer_timer.stop() func handle_collisions()->void: