refactored movement script
This commit is contained in:
parent
7af7aa8ded
commit
2c3a911fc9
3 changed files with 17 additions and 16 deletions
|
@ -1,17 +1,18 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 50
|
||||
@export var gravity = 50
|
||||
@export var jump = 700
|
||||
@export var speed = 340;
|
||||
@export var gravity = 50;
|
||||
@export var jump_count = 2;
|
||||
@export var jump_strength = 700;
|
||||
|
||||
var max_jumps = 2;
|
||||
var jumpcount = 2;
|
||||
|
||||
var input_direction = 0
|
||||
var jump_count_current = 2;
|
||||
var input_direction = 0 #To keep track of which direction we where moving in last frame
|
||||
|
||||
func get_input():
|
||||
|
||||
var left = Input.is_action_pressed("player_left")
|
||||
var right = Input.is_action_pressed("player_right")
|
||||
|
||||
if left and right:
|
||||
input_direction = input_direction
|
||||
elif left:
|
||||
|
@ -21,17 +22,18 @@ func get_input():
|
|||
else :
|
||||
input_direction = 0
|
||||
|
||||
|
||||
velocity.x = input_direction * speed
|
||||
if Input.is_action_just_pressed("player_jump") and jumpcount > 0:
|
||||
velocity.y = -1 *jump
|
||||
jumpcount = jumpcount-1
|
||||
elif Input.is_action_pressed("player_jump"):
|
||||
|
||||
if Input.is_action_just_pressed("player_jump") and jump_count_current > 0:
|
||||
velocity.y = -1 * jump_strength
|
||||
jump_count_current = jump_count_current-1
|
||||
elif Input.is_action_pressed("player_jump"): #Fall less fast if we keep holding the button
|
||||
velocity.y += -1 * 20
|
||||
|
||||
if is_on_floor():
|
||||
jump_count_current = jump_count
|
||||
|
||||
func _physics_process(delta):
|
||||
if is_on_floor():
|
||||
jumpcount = max_jumps
|
||||
get_input()
|
||||
velocity.y += gravity
|
||||
move_and_slide()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue