Dynamic Collisionshapes

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

Hi,

so I’m currently playing around with voxels a littble bit and with that, dynamicly create the shapes for each voxel that is in a chunk. The collision etc. works just fine, but actually it wouldn’t make much sense to have these collisionshape always activated, so is there a nice way to disable them to save some performance? I also notice that the collisionshape that I’m generating never get displayed in the game view if I enable the option “Visible Collision Shape” in the editor. Only shapes that was created in the editor will be shown. Is this intended?

How are you creating the collision shapes? Are you instancing CollisionShape nodes? If you do, keep in mind these are not intented to be created by the game, they are editor helpers.
Now, about seeing them… I have no idea why they don’t show :confused:

Zylann | 2016-10-01 15:03

This is how I create the collision shape:

Maybe they don’t show up in the game, because I don’t use the editor helper class, because this class manage this behavior?

Nophlock | 2016-10-02 10:41

Oh and by the way, is there a way to manipulate a mesh? The only thing I found so far was the “meshDataTool” but this only allows to manipulate vertices and not to remove them, this is the same case for the “surfaceTool”. Is there no class/helper to actually remove unwatend vertices?

Nophlock | 2016-10-02 10:53

I use SurfaceTool to create a mesh, I don’t know of other ways. But I’m looking forward to discover better ways because SurfaceTool is not as efficient as it could be, I made a voxel prototype like you and I basically rebuild chunks everytime at least one voxel changed in it. It’s not a problem, but the meshing process is too slow and could be greatly improved with a more direct access to how geometry is built.

I still have no idea about previewing 3D collision shapes, never played with them so far :confused:

Zylann | 2016-10-02 14:00

Yeah that was exactly my aproach too, but now I’ve switched it in that way, that a chunks gets splittet into submeshes which contains 64 voxels. With this approach removing voxel goes quite fast, since I only need to renew a small part of the chunk/mesh and with threading it’s not even noticeable that the pc takes some time to regenerate it.

Now back to topic ^^ is there a way to disable collision shapes for a while or do I need to dynamicly remove and add them, if an entity comes near it?

Nophlock | 2016-10-03 17:38

If disabling is not an option, I would remove them from all physics layers (making them effectivelly colliding with nothing) and pool them in a list. Then when I need an active collider, I would pick one from the pool and set it on the appropriate position and collision layers. It should be efficient because there will be minimal memory allocations. However I never tried this approach with voxels, I usually implemented my own collider specialized for voxel grids. Thought doing it in GDScript would be too slow :stuck_out_tongue:

Zylann | 2016-10-03 18:27

Sorry for the late reply, it actually seems like there is no real way to disabling a created collision shape, at least I didn’t found one. So your idear seems like the best solution for this.

Nophlock | 2016-10-08 14:01