Check collision after instance a new scene (body)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By NVA_Lee22
:warning: Old Version Published before Godot 3 was released.

I want to check if a new instanced scene has collision on its “spawn” position.

How can i do that ?
(maybe Area2D overlapping or change from static to kinematic body for collision check?)

What i have:

var myScene = preload(scenePath)
var sceneInstance = myScene.instance()
add_child(sceneInstance)
sceneInstance.set_pos(Vector2(50,50))
# HOW TO CHECK IF THE POSITION IS USED BY ANOTHER BODY?
# if sceneInstance is placed on another object:
# move away OR queue_free()
:bust_in_silhouette: Reply From: eons

You can use Shape2D api if you have areas or a list of known bodies to test (testing shape against shape with corresponding object transforms).

Or test collisions using Physics2DDirectSpaceState.intersect_shape (only works on bodies, I think).
http://docs.godotengine.org/en/stable/classes/class_physics2ddirectspacestate.html

Thanks, but i didn´t get this to work. How i use this Shape2D class ?

For example i have a Area2D Node and as child a CollisionPolygon2D:

# How to use it ?
get_node("Area2D_Name").Shape2D.collide()

EDIT:

Okay i got it

 get_node("Area2D_Name/CollisionShape2D").get_shape().collide(arg1,arg2,arg3)

NVA_Lee22 | 2017-07-14 15:20

The Problem now is that i only can check one shape with another specific shape which are declared in the check function. Is there a way to check if the Object is colliding with any other shape of the world (not just a specific one to check) ?

NVA_Lee22 | 2017-07-14 15:55

If are areas, you need to find a way to retrieve them all (grouping them could be the best option), then get the target area’s shape and transform to test against. your design may make things easier or harder.

Some steps to reduce the areas you are checking may be possible, like checking (square) distance to the target point as a filter, or rules for group names according to “zones” (design, again).

eons | 2017-07-15 03:00

:bust_in_silhouette: Reply From: NVA_Lee22

So i solved it in another way. After instance alle objects i wait 0.05 sec and run another function in every single object which checks itself for overlapping bodies. For that each object it self need a Area2D and the CollisionShape to get Area2D.get_overlapping_bodies()