So, the movement code in my game broke. It's only the player's movement that has broke and all other things like enemies have normal movement
extends CharacterBody2D
@onready var _animated_sprite = $AnimatedSprite2D
#CONSTs
const MAX_SPEED = 300
const ACCEL = 1000
const friction = 900
#HP and firing vars
var noHP = true
var hp = 10 #starting hp
var input = Vector2.ZERO
var charge = 0 # charge of bullet.
var _canFire = true # if off, can't shoot
#UI Vars
var noCharge = true
var ChargeBar = load("res://Scenes/UI/charge_bar_v3.tscn")
var chargeBar = ChargeBar.instantiate()
var HPBar = load("res://Scenes/UI/hp_bar_v3.tscn")
var hpBar = HPBar.instantiate()
#Pause Vars
var paused = false
var pause = self.get_parent()
var canPause = true
#Movement Functions
func get_input():
input.y = int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up"))
return input.normalized()
func movement(delta):
get_input()
if input == Vector2.ZERO:
if velocity.length() > (friction* delta):
velocity -= velocity.normalized() * (friction * delta)
else:
velocity = Vector2.ZERO
else:
velocity += (input *ACCEL * delta)
velocity = velocity.limit_length(MAX_SPEED)
func shoot():
if charge < 10:
var bullet_uncharged = load("res://Scenes/Bullets/Bullet_Uncharged.tscn")
var bullet = bullet_uncharged.instantiate()
bullet.position = get_global_position()
get_parent().add_child(bullet)
$BulletTimer.start()
_canFire = false
else:
var bullet_charged = load("res://Scenes/Bullets/bullet_charged.tscn")
var chargedBullet = bullet_charged.instantiate()
chargedBullet.position = get_global_position()
get_parent().add_child(chargedBullet)
$BulletTimer.start()
_canFire = false
move_and_slide()
func chargeFunc():
if noCharge == true:
get_parent().add_child(chargeBar)
noCharge = false
chargeBar.max_value = 10
func hpFunc():
if noHP == true:
get_parent().add_child(hpBar)
noHP = false
hpBar.value = hp
hpBar.max_value = 10
func _physics_process(delta):
chargeFunc()
hpFunc()
movement(delta)
chargeBar.value = charge
if hp == 0:
get_tree().change_scene_to_file("res://Scenes/Game_Over.tscn")
if charge >= 10:
_animated_sprite.play("Pulse")
if Input.is_action_pressed("attack") && charge < 10:
charge += 0.25
if Input.is_action_just_released("attack") && _canFire == true:
shoot()
charge = 0
chargeBar.value = charge
func _on_timer_timeout():
_canFire = true
func _on_hurtbox_area_entered(_area):
hp -= 1
func _on_pause_timer_timeout():
canPause = true