collision check using signals. (raycast / collsionshape)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PepijnWe

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):
	print("1")
	block = true


func _on_Player_2_body_exited(body):
	print("2")
	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:

raycast.force_raycast_update()

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.