kuligs2 Sorry. I was a little confused. For the implementation of
if direction_input:
velocity = ...
do you mean creating a system that specifies velocity when direction_input and when not direction_input? I wasn't quite sure where you meant to implement it and the reason.
In my CharacterBody2D, I have physics_process()
func _physics_process(delta: float): # delta variable has value of the frame time that engine passes to function.
# local variables
var collision = move_and_collide(velocity * delta) # define collision (add true to affect only collision and not movement)
var direction_input = Input.get_vector("left", "right", "up", "down")
var direction_facing = direction_last # last direction is direction you are facing
direction_last = get_direction() # returns value from respective function
And within physics_process I have a state the defines velocity
States.MOVE:
if collision and collision.get_collider().is_in_group("bumper_group"):
state = States.BOUNCE
elif direction_input.abs().length() < 0.5:
state = States.IDLE # change state
elif Input.is_action_pressed("space_bar") and can_charge_player:
state = States.CHARGE # change state
else: # run move code
speed = speed_move # set speed to move speed
velocity = direction_input * speed # move
as well as these functions underneath, but called within physics_process
func apply_acceleration(direction_input) -> void: # currently, acceleration is only being used for SPIN
speed = speed_spin
velocity = velocity.move_toward(direction_input * speed, acceleration) # to, by
func apply_deceleration() -> void:
velocity = velocity.move_toward(Vector2.ZERO, deceleration) # decelerate velocity
speed = move_toward(speed, 0, deceleration) # decelerate speed
Do you think that something here is overriding Area2D's velocity reference somewhere?