The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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()
in Engine by (42 points)

2 Answers

0 votes
Best answer

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.getoverlappingbodies()

by (42 points)
+1 vote

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).
http://docs.godotengine.org/en/stable/classes/class_shape2d.html

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

by (7,890 points)

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)

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) ?

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).

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.