0 votes

How use this signal in script?
where i get this vars - int bodyid ,ObjectBody,int bodyshape, etc.
...this signal is used to detect a collision if I want only a specific object, right?
Thanks for help

in Engine by (450 points)

1 Answer

+1 vote
Best answer

When you use the signal bodyentershape, the callback function gets all these parameters.

The first is the ID of the node (I don't know why, it should be the area...)
The second is a reference to the body itself (the one who entered the area, same id).
Then the next is the index of the shape that belongs to the body (you can have many shapes in a single body), the one that entered the area.
The last one is the index of the shape of the area (could have many too), the shape where the body entered.

This is useful when you have different reactions depending on the shapes (of a single body/area) that fired the signal.

by (7,868 points)
selected by

Thank you very much...it's clear for me now.

Useful information, but how can I get more information on the bodyshape I hit?
I'm designing bullet that can pass through some hitbox. Example : I'm doing a fence that bullet can pass through but KinematicsBody2D can't. Poles(side of the fence) will stop bullet but the grid(middle of the fence) will not stop bullet. How can I get the object to know if CollisionShape2D.is

Something I could call like that :
if (body.getCollisionShape(body_shape).is_in_group("BulletPassThrough")): print("Do nothing") else: print("Hit something Bullet will be destroy") queue_free()

I've been reply on reddit and I think this can be useful here : https://www.reddit.com/r/godot/comments/97cy41/area2d_detect_which_collision_shape_it_hit/

For that case, just use layers.

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.