Fixed movements greatly. Not sure why jumping got broken, was working well then stopped.

This commit is contained in:
Hyperling 2023-10-01 20:19:01 -07:00
parent 13f297bc97
commit 2163dec3ec

View File

@ -6,12 +6,13 @@ extends CharacterBody2D
var x_dir = 0 var x_dir = 0
var moving = false var moving = false
var accel = 100 var accel = 50
var maxspeed = 125 var maxspeed = 250
var friction = 50 var friction = 500
var y_dir = 0 var y_dir = 0
var jumping = false var jumping = false
var falling = true
var jump_speed = 1000 var jump_speed = 1000
var gravity = 250 var gravity = 250
@ -26,22 +27,23 @@ func _ready():
func _physics_process(delta): func _physics_process(delta):
## Controls ## ## Controls ##
# Movement # Movement
if Input.is_action_pressed("ui_left"): if Input.is_action_pressed("ui_left"):
moving = true velocity.x += -accel #* delta
velocity.x += -accel * delta
if Input.is_action_pressed("ui_right"): if Input.is_action_pressed("ui_right"):
moving = true velocity.x += accel #* delta
velocity.x += accel * delta
# Jump
if Input.is_action_pressed("ui_up"): if Input.is_action_pressed("ui_up"):
if !jumping: if !jumping && !falling:
jumping = true jumping = true
velocity.y += -jump_speed * delta velocity.y = -jump_speed #* delta
print_debug(str(velocity.y))
if Input.is_action_pressed("ui_down"): # Crouch
velocity.y += accel * delta #if Input.is_action_pressed("ui_down"):
# velocity.y += accel #* delta
# Combat # Combat
#TBD #TBD
@ -54,19 +56,17 @@ func _physics_process(delta):
if round(velocity.x) == 0: if round(velocity.x) == 0:
velocity.x = 0 velocity.x = 0
x_dir = 0 x_dir = 0
moving = false
## Gravity ## ## Gravity ##
if velocity.y != 0: if round(velocity.y) == 0:
y_dir = velocity.y / abs(velocity.y)
if round(velocity.y) == 0:
velocity.y = 0
y_dir = 0
if jumping: if jumping:
velocity.y -= gravity * -x_dir * delta jumping = false
else: falling = true
jumping = false elif falling:
falling = false
velocity.y += gravity * delta
## Speed Limits ## ## Speed Limits ##
@ -78,7 +78,14 @@ func _physics_process(delta):
move_and_slide() move_and_slide()
print_debug("X Dir = " + str(x_dir) + ", X Speed = " + str(velocity.x)) print_debug(
print_debug("Y Dir = " + str(y_dir) + ", Y Speed = " + str(velocity.y)) "X Dir = " + str(x_dir)
+ ", X Speed = " + str(velocity.x)
+ "\n"
+ "Y Dir = " + str(y_dir)
+ ", Y Speed = " + str(velocity.y)
+ ", Jumping is " + str(jumping)
+ ", Falling is " + str(falling)
)
pass pass