So basically, I am creating a lot of static bodies in my scene(we're talking thousands) and i wanted to see if there was a way to only have one static body as a parent and my game objects to be collisionshape children of that parent. the thing is, the whole reason each object had a static body is so I can interact with it through a raycast. when the scene is made up of one static body, raycast.get_collider() always gives the static body. I was wondering if its even possible to get the individual collisionshapes with raycasting.

thank you and have a nice rest of your day!

  • xyz replied to this.
  • Rose19 Haven't checked it, but I think get_collider_shape() simply returns the index of the shape node, as it appears in the scene tree. So calling body.get_child(ray.get_collider_shape()) may do the trick.

    Btw get_instance_id() is a method of Object class, and has the entirely different purpose.

    xyz this did not work. so i went and added a static body with multiple collsionshape3Ds and used the get_collider_shape() on it. then i used the instance_from_id() method to get the object. it crashed. so i go to the staticbody and add a script to get all the children id using get_instance_id() and print them. it gave me a completely different ids from ray.get_collider_shape() .

    To put it simply, the Shape id and the CollisionShape3D instance id are NOT the same. so now i need to find a way to get the collisionshape3d id.

    i tried to get the collisionshape's shape id with the following code on my static body.

    and the result is even wierder.

    for the 4 collisionshape3ds under the staticbody, i got different ids for the node itself, the shape of that node, and the ray.get_collider_shape() . (the 0 to 3 below the text was from the raycast which seems to be in order of the editor hierarchy )

    so, my question is, how do i even use the ray.get_collider_shape()? the id it gives seems completely worthless and there is no function to use this id to get the CollisionShape3D owner of that shape.

    thanks again for replying.

    • xyz replied to this.

      Rose19 Haven't checked it, but I think get_collider_shape() simply returns the index of the shape node, as it appears in the scene tree. So calling body.get_child(ray.get_collider_shape()) may do the trick.

      Btw get_instance_id() is a method of Object class, and has the entirely different purpose.

        xyz you are a genius. body.get_child(ray.get_collider_shape()) works exactly like i wanted , I'm able to get every collisionshape node separately and it even works when adding new ones at runtime.

        thank you so much for the help!