0 votes

I want to check if a new_position is available, if this position is available I want the node to move there.

I'm using an area2D with a collisionShape that gets moved to the desired new_positon. It needs to check if the spot is available, and then move there if it is available.

Here is a example of how it works

Example code:

func _on_Player_2_body_entered(body):
    block = true

func _on_Player_2_body_exited(body):
    block = false

func move(dir):
    shape.position = new_position
    if block == false:
        self.position = new_postion

The problem is that the collisionshape only updates after the code is run completely, causing a delay, making it available to move trough walls.

I tried using Raycast first, which has the following function:


This fixed the delay, but the issue with a Raycast is that it checks in a line, and not in a point. So maybe a similar function for signals could work.

I'm looking for a way to check if a collision occurs at that point. But i'm out of ideas, and google searches. I hope one of you has an idea how to fix this.

in Engine by (51 points)

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.