if i press left and right key at the same time, positive and negative positions neutralize each other. and character wil stop. i want control like Atari 2600 River Raid movement . If two keys are pressed at the same time, select the last one pressed
. River raid is designed for joystick. I'm talking about Stella emulator controls. The javascript version has similar controls but slightly different -> https://www.retrogames.cz/play_036-Atari2600.php?language=EN
How can i do with Gdscript? thanks.
extends KinematicBody2D
var speed = 400
var acceleration = 0.1
var velocity = Vector2.ZERO
var input_velocity = Vector2.ZERO
func _physics_process(delta):
input_velocity = Vector2.ZERO
if Input.is_action_pressed("ui_right"):
input_velocity.x += 1
if Input.is_action_pressed("ui_left"):
input_velocity.x -= 1
input_velocity = input_velocity.normalized() * speed
if input_velocity.length() > 0:
velocity = velocity.linear_interpolate(input_velocity, acceleration)
else:
velocity = Vector2.ZERO
velocity = move_and_slide(velocity)