[Godot 4.4] How to Make a Player Limit Area Globe

Godot Version

4.4.1

Question

How can I create an inverted CollisionShape3D sphere without using multiple collision shapes?

I want my player and physics objects to be constrained within this circular area:

However, I can’t find the old option to invert the collision. Am I missing something?

I don’t see anything obvious, but if you’re just trying to constrain things to a hemisphere, that’s fairly easy; use normal collision for the ground plane, and clamp object positions to within the hemisphere’s radius of the hemisphere’s origin.

    if global_position.distance_to(ORIGIN) > RADIUS:
        global_position = ORIGIN - (global_position.direction_to(ORIGIN) * RADIUS)

You can do the check with distance_squared_to() to make it cheaper.

1 Like

Use the body_exited signal instead of the body_entered signal.

Can you hook up body_exited as a constraint for move_and_slide()? I think that’s what OP wants; to be able to set up inclusive rather than exclusive areas for physics movement.

This would kinda work for the player, but my game has physics calculations that needs to be constrained inside that area too. If I apply this method I would need to make constrains for every map I create in the future.

This is exactly what I need. I’m pretty sure that some time ago we had this option in the CollisionShape nodes, but I can’t find it in the 4.4 version.

No, I don’t think you can. Oh… I just had an idea though.

Ok, I’ve never done this before, but I did a quick test:

  1. Add a CSGCombiner3D node.
  2. Add a CSGBox3D node and a CSGSphere3D (in that order) as children and make them the size and position you want.
  3. Select the CSGSphere3D node
  4. In the Inspector under the CSGShape3D section change the Operation to Subtraction.
    image
  5. Select the CSGCombiner3D node.
  6. In the Toolbar click on the CSG Dropdown Menu and select Bake Collision Shape - a CSGBakedCollisionShape3D node will be added to the node tree.
  7. Create a StaticBody3D node.
  8. Move the CSGBakedCollisionShape3D node under the StaticBody3D node

If you want the shape to be visible, you can add also select Bake Mesh Instance from the CSG Menu and move the resulting CSGBakedMeshInstance3D node under the StaticBody3D node as well.

This is insane! Thank you!

1 Like

Props also to Zenva. One of their lessons used the CSGCombiner3D node which I had never seen before. I did the lesson a couple days ago and even though they didn’t do this, I put together some things I learned from a post by @Demetrius_Dixon asking about CSGBoxes and collisions. (That’s when I found out that you can bake CSGs.) So I just took my Blender knowledge and took a shot.

So I really recommend the Zenva Humble Bundle I posted about here: For People Trying To Learn Godot Because I have learned about all sorts of little 3D, UI, and shader things I didn’t know before.

1 Like