Is it possible to create APhysicsVolume from C++?

I want some areas of level to have zero gravity. Level is grid of cubes. I spawn APhysicsVolume at required places (world->SpawnActor).
However the volumes have no any shape. Is it possible to specify cube shape for APhysicsVolume from C++ code? Specifying arbitrary shape would be even better. Because it is better to spawn one volume with complex shape instead of ten or hundred individual volumes.

You could use a 3D modeling tool such as maya to create a custom collision geometry and then insert that into your level. When something collides with it, you can create an event. Within that event, you can then write your handling code.

Alternatively, you’d probably be looking at creating a custom geometry object in C++.

One other thing you can look into is using the BSP tool to create the volumes and collision areas, but just don’t render the BSP and set collision to “overlap”.

The level is randomly generated at runtime. So it is impossible to prepare any collision meshes beforehand.

Okay… so… that means you’re going to have to generate your collision volume at runtime as well. If you have a block/tile based world, you’ll want to create those collision volumes as cubes.

Obviously, you’ll want to create as few cubes as possible to optimize for runtime performance. If your game doesn’t have elevation (isometric like an RTS), you can get away with using a grid of cubes. If your game does have elevation (like minecraft), you’ll need to have a block of cubes.

There are procedural techniques you can use to fill a volume with cubes. I personally would look at using an Octree with recursion to fill a region. The recursive question I would be asking is, “what is the largest cube I can use to most fill this region?” and then keep subdividing until there is no empty space left to fill. It’s an interesting problem to solve. I think it would take about 1-2 weeks for me to do, so don’t expect it to be super fast and easy.

There is no elevation. I did not think about trying to fit the biggest parallelepiped. Thank you for idea. That would save some amount of cubes. Still I don’t know how to create APhysicsVolume. Current fallback solution is to use UBoxComponent and custom collision channel. The next step is to fugure out what to do with character to simulate zero gravity and friction.

Okay, no elevation makes this super easy. You’re essentially working with a 2D plane. The best data structure for you would be a QuadTree.

One design question you’ll have to figure out is if a character can be partially in a no-gravity zone. ie, can they ever be 50% overlapped? If it’s either 0 or 100%, then that makes things super simple for your quad tree implementation. All you’d have to do is test whether the actor location is within a no gravity zone. With a quad tree, you can do this in O(Log base 4 N) time.

Note: You wouldn’t even need to worry about physics volumes or cubes here. You’re just checking a point to see if its contained within a rectangle, and then toggling gravity on or off based on the result.

Thank you for the help.