Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | sempiro |
I want to stop two opposite keys from cancelling each other when they get pressed at the same time. For example if I press up, then down without releasing the up key the player goes down instead of freezing in place. My code:
extends KinematicBody2D
func _ready():
pass
var MOVE_SPEED = 300
func _physics_process(delta):
var move_vec = Vector2()
if Input.is_action_pressed("ui_up"):
move_vec.y -= 1
if Input.is_action_pressed("ui_down"):
move_vec.y += 1
if Input.is_action_pressed("ui_left"):
move_vec.x -= 1
if Input.is_action_pressed("ui_right"):
move_vec.x += 1
move_vec = move_vec.normalized()
move_and_collide(move_vec * MOVE_SPEED * delta)