#can only move along the x axis

1 messages · Page 1 of 1 (latest)

steady igloo
#

can anyone help me out ? i cant really understand why but i can only go left and right, the other options dont word, this may also be an issue with my binds so ill link a screenshot

extends CharacterBody2D

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
    if Input.is_action_just_pressed("left"):
        position.x += 0.5 * delta
    elif Input.is_action_just_pressed("right"):
        position.x -= 0.5 * delta
    elif Input.is_action_just_pressed("up"):
        position.y += 0.5 * delta
    elif Input.is_action_just_pressed("down"):
        position.y -= 0.5 * delta
pure cloak
#

Use is_action_pressed() function

#

For left movement use - (minus) operator , for right + operator,
Up - operator and down +operator

rose saffron
#

use Input.get_vector instead

#

makes it all much cleaner

#
var direction = Input.get_vector("left", "right", "up", "down")
velocity = direction * SPEED
move_and_slide()
#

and since you are using a CharacterBody2D use move_and_slide or move_and_collide

steady igloo
lone verge
#

You're using a CharacterBody2D node. If you move the position directly you won't get collisions to work. The CharacterBody2D node works through velocity and move_and_slide()

#

Are you trying to lock down movement to a single axis at a time?