Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | jackash |
How to detect, what nodes intersect some coordinates (for example mouse coordinates)?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | jackash |
How to detect, what nodes intersect some coordinates (for example mouse coordinates)?
Reply From: | Toshio Araki |
See this tutorial:
In particular this part (for 3D just use get_world and Vector3 as parameters):
var space_state = get_world_2d().direct_space_state
# use global coordinates, not local to node
var result = space_state.intersect_ray(Vector2(0, 0), Vector2(50, 100))
You will get a dictionary as a response, and, I’m guessing, the collider is the node you intersect with.
{
position: Vector2 # point in world space for collision
normal: Vector2 # normal in world space for collision
collider: Object # Object collided or null (if unassociated)
collider_id: ObjectID # Object it collided against
rid: RID # RID it collided against
shape: int # shape index of collider
metadata: Variant() # metadata of collider
}
Reply From: | MagnusS |
Alternatively you could add a collision object to your node and use its _input_event() to react to a mouse click if that’s what you want to do.