physics.rayCast() vs multi-element physics bodies

Hi there,

i want to get a element out of a multi-element physics body when returning “hits” from the raycast.

Currently im only getting the whole object but not the single elements within the object itself.

Can anyone help me please?

Cheers,

Amplexor

Hi @Amplexor,

Unfortunately, raycasts don’t return the specific body element in a multi-element body that the ray came into contact with. So, if this is your requirement, you might need to find a workaround. While not “ideal”, you could put a new physical object at the ray’s collision point… just a small circular sensor of radius 2-4 for example… and then, in the collision handler for the multi-element body, detect collision between that little sensor object and the element that it came into contact with. At that point, the little sensor object could be removed. I think that would give you pretty good accuracy on exactly which element the ray came into contact with.

Best regards,

Brent

Hey @Brent,

Thank you for your fast response!

What an great idea! And it works, thank you very much!

Kind regards,

Amplexor

Hi @Amplexor,

Unfortunately, raycasts don’t return the specific body element in a multi-element body that the ray came into contact with. So, if this is your requirement, you might need to find a workaround. While not “ideal”, you could put a new physical object at the ray’s collision point… just a small circular sensor of radius 2-4 for example… and then, in the collision handler for the multi-element body, detect collision between that little sensor object and the element that it came into contact with. At that point, the little sensor object could be removed. I think that would give you pretty good accuracy on exactly which element the ray came into contact with.

Best regards,

Brent

Hey @Brent,

Thank you for your fast response!

What an great idea! And it works, thank you very much!

Kind regards,

Amplexor