Currently making an Enter the Gungeon like game for a game jam, but for some reason my depending on what direction I’m looking, certain inputs don’t work depending on what direction I’m rolling in. Despite the fact that Q and E are both bound to the dodge input, I can’t dodge roll upwards or downwards to the right if I press D, or upwards or downwards to the left if I press E. I’d like it for the dodge roll to work in all directions no matter what key I’m pressing, help is appreciated!
extends CharacterBody2D
var input_direction = Vector2.ZERO
var can_slash = true
var can_roll = true
var roll_directions = [Vector2(1,0), Vector2(-1,0), Vector2(0,1),
Vector2(0,-1), Vector2(1,1).normalized(), Vector2(-1,1).normalized(),
Vector2(1,-1).normalized(), Vector2(-1,-1).normalized()]
@export var speed = 120
@onready var collision = $"/root/Main/Tulip/Tulip's Sword/CollisionShape2D"
var is_rolling = false
var roll_direction = Vector2.ZERO
func get_input():
input_direction = Input.get_vector("left", "right", "up", "down")
if not is_rolling:
velocity = input_direction * speed
func get_locked_direction():
var angle = input_direction.angle()
var best_direction = roll_directions[0]
var smallest_angle_diff = abs(angle - best_direction.angle())
for direction in roll_directions:
var diff = abs(angle - direction.angle())
if diff < smallest_angle_diff:
best_direction = direction
smallest_angle_diff = diff
return best_direction
func _physics_process(_delta):
get_input()
if Input.is_action_just_pressed("roll") and can_roll:
if can_roll:
roll_direction = get_locked_direction()
$"Dodge Roll Time".start()
$CollisionShape2D.disabled = true
can_roll = false
speed = 200
print("huzzah")
is_rolling = true
velocity = roll_direction * speed
move_and_slide()