0 votes

The priorities are up and down, if there's no free space in those directions, then right or left. I want up and down work like godot's default system with right and left (depending on which side it's the fastest way to get the character out).

in Engine by (122 points)

2 Answers

0 votes

You'll want to use grid-based movement with a standardized tileset (ie. all tiles are 16 * 16 pixels).

by (96 points)
0 votes

Use a raycast. Create a new function and use it to change the cast_to property and check is_colliding() and use return to stop the function when the raycast hits.

func _process(delta):
    RaycastCheck()

func RaycastCheck():
    $raycast.cast_to = Vector2.UP
    if $raycast.is_colliding():
        #move up
        return
    $raycast.cast_to = Vector2.DOWN
    if $raycast.is_colliding():
        #move down
        return
    $raycast.cast_to = Vector2.LEFT
    if $raycast.is_colliding():
        #move left
        return
    $raycast.cast_to = Vector2.RIGHT
    if $raycast.is_colliding():
        #move right
        return
by (3,259 points)

But the priorities still are right and left and not up and down like i want.

It shouldn't but if it only goes right try using yield(get_tree, "idle_frame") each time after setting cast_to to allow is_colliding() to return an accurate result.
Raycasts are sometimes better used in _physics_process so you can try using four raycasts for each direction and using if else statements.

How i make the priorities up and down rather than right or left?
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.