0 votes

Currently I have my player character set up to move exactly 32 pixles every time the arrow key is pressed. The problem is that I can't collide with any of the walls, static bodies, or anything else i am supposed to. I know my walls are collide-able because when using the "8-way movement" on the Godot Docs movement page, i can collide with my tiles just fine. Sadly using the speed var and Vector2() movement doesn't let me move exactly 32 pixels.

What I have for movement at the moment:

func get_input():
if Input.is_action_just_pressed('ui_right'): 
    position.x += 32
if Input.is_action_just_pressed('ui_left'):
    position.x -= 32
if Input.is_action_just_pressed('ui_down'):
    position.y += 32
if Input.is_action_just_pressed('ui_up'):
    position.y -= 32

Now I figure this is kind of like teleportation, which might be why I can't run into walls, i have yet to figure out an alternative way of getting this kind of exact movement.
Please let me know your thoughts and ideas.

In the end I need my character to run into walls and move exactly one 'Square' every time my arrow key are pressed. Thank you all for your help.

in Engine by (12 points)

You could use 4 RayCast2D which check the space in the direction you want to move, and disable movement in that direction if it's colliding with the TileMap. Probably not the best solution, but that's how I'd do it.

Thank you, I was thinking about that, but I do worry that it will take to much processing power. I will probably need four different ray-cast on my player's character, and each NPC that moves. I Will go ahead and try it though maybe I am over estimating the amount of processing that would take.

you can disable all raycasts and only enable the ones you need to check when you need to check

so if presed "up" you turn on the up_raycast, check it, and disable it again

you can also have multiple raycasts being turned on, checked, and off in a for loop to check multiple collisions

That is, a really good idea thank you, and with all of that it should work great.

Please log in or register to answer this question.

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.
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 webmaster@godotengine.org with your username.

Categories