- Edited
I'm still getting used to coding, but I have this variable here for my CharacterBody2D script:
var facing = dir_last # see get_directon() function to see what dir_last equals
and some code that makes my character bounce off collisions:
States.BOUNCE:
if ! collision:
if velocity.is_zero_approx():
state = States.IDLE # change state
elif Input.is_action_pressed("move"):
state = States.MOVE # change state
elif Input.is_action_just_released("blast"):
state = States.BLAST # change state
elif ! Input.is_action_pressed("move"):
apply_deceleration(delta)
deceleration = deceleration_blast
else:
velocity = velocity.bounce(collision.get_normal())
and I tried to make this code to get and update the last direction the character is facing based on the direction velocity moves them in:
func get_direction():
# cardinal
if velocity.x < 0:
dir_last = Vector2.LEFT
elif velocity.x > 0:
dir_last = Vector2.RIGHT
if velocity.y < 0:
dir_last = Vector2.UP
elif velocity.y > 0:
dir_last = Vector2.DOWN
# diagonal
if velocity.x < 0 and velocity.y < 0:
dir_last = Vector2.LEFT + Vector2.UP #NW when bouncing down?
elif velocity.x > 0 and velocity.y < 0:
dir_last = Vector2.RIGHT + Vector2.UP #NE when bouncing up?
elif velocity.x < 0 and velocity.y > 0:
dir_last = Vector2.LEFT + Vector2.DOWN #SW # when bouncing up?
elif velocity.x > 0 and velocity.y > 0:
dir_last = Vector2.RIGHT + Vector2.DOWN #SE # when bouncing down?
And what I'm trying to figure out is why, when after bouncing off collision, does the facing (dir_last) only get updated to diagonal directions, even if the character is bounced in a cardinal direction?
I've tried looking at my code, but I just can't think of what it might be or what could cause that, so I thought I'd ask for help while I continue to try to figure it out.