Basically what the title says. When I use a controller and try to move while using my roll that I coded, it moves only in cardinal and diagonal directions. It’s not fluid, despite the fact that the base movement is.
Code:
extends CharacterBody2D
var direction: Vector2 = Vector2.ZERO
var last_direction: Vector2 = Vector2.RIGHT
var is_rolling: bool = false @export var speed: int = 75 @onready var anim_player = $AnimationPlayer @onready var sprite = $Sprite2D
func _process(delta):
if not is_rolling:
direction = Input.get_vector(“p1left”, “p1right”, “p1up”, “p1down”).normalized()
if direction.length() > 0:
anim_player.play(“cowboyRun”)
else:
anim_player.play(“cowboyIdle”)
if direction.length() > 0:
last_direction = direction.normalized()
else:
direction = last_direction
if Input.is_action_pressed("p1left"):
direction.x = -1
if Input.is_action_pressed("p1right"):
direction.x = 1
if Input.is_action_pressed("p1up"):
direction.y = -1
if Input.is_action_pressed("p1down"):
direction.y = 1
direction = direction.normalized()
if direction.x < 0:
sprite.flip_h = true
elif direction.x > 0:
sprite.flip_h = false
if Input.is_action_just_pressed("p1roll") and not is_rolling:
anim_player.play("cowboyRoll")
is_rolling = true
speed = 125
if anim_player.is_playing() == false and is_rolling:
is_rolling = false
speed = 75
func _physics_process(delta):
velocity = direction * speed
move_and_slide()
This part of the code makes it so that you only move in cardinal / diagonal directions.
if Input.is_action_pressed("p1left"):
direction.x = -1
if Input.is_action_pressed("p1right"):
direction.x = 1
if Input.is_action_pressed("p1up"):
direction.y = -1
if Input.is_action_pressed("p1down"):
direction.y = 1
direction = direction.normalized()
I think this might only get called if you are rolling, so that is why you can move normally outside of rolls. If you want to roll in any direction you should just keep direction at the value of last_direction.
I don’t understand what you’re saying. Like, I understand why my issue occurs, because I handle movement differently during a roll than normally, but I don’t understand what you’re saying to do to fix it. If you meant have the replace the line “direction = direction.normalized()” with “direction = last_direction,” that just makes it so that I cannot control the roll at all.
(Also I should’ve mentioned that the “last_direction” variable makes it so that the direction I last went in is stored, so that if I am not moving, the game still knows where to send me if I roll.)
Oh I see. In some other games players cannot change the roll direction mid-roll, but you want that to happen.
Anyway, you only get the input vector when the character is not rolling, so the character can’t change their direction during that time. If you get the input vector all the time, the character will be able to change their direction mid-roll.