0 votes

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

func _physics_process(delta):
    var 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)
asked Aug 7 in Projects by razah (118 points)

1 Answer

0 votes
Best answer

Here's an example of one possibility. Just season to taste...

extends Node2D
var x_delta = 0

func _physics_process(delta):
    var input_velocity = Vector2.ZERO

    if Input.is_action_just_pressed("ui_right"):
        x_delta = 1

    if Input.is_action_just_pressed("ui_left"):
        x_delta = -1

    if Input.is_action_just_released("ui_right") && x_delta > 0:
        x_delta = 0

    if Input.is_action_just_released("ui_left") && x_delta < 0:
        x_delta = 0

    input_velocity.x = x_delta

    print(input_velocity.x)
answered Aug 7 by jgodfrey (6,576 points)
selected Aug 7 by razah
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.