How to use signal - body_enter_shape (int body_id, ObjectBody, int body_shape, int area_shape) ?

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

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

:bust_in_silhouette: Reply From: eons

When you use the signal body_enter_shape, 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.

Thank you very much…it’s clear for me now.

Bishop | 2017-05-28 00:54

Useful information, but how can I get more information on the body_shape 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_in_group(“BulletPassThrough”).

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 : Reddit - Dive into anything

Maxime | 2018-08-14 23:40

For that case, just use layers.

eons | 2018-08-15 09:54