Point Update Collider at runtime

Hi, I’m new to Xenko and trying to identify limitations for a game design I have in mind, before i fully engage with it.

Intent
What I’m trying to achieve is this: Imagine a procedurally generated terrain that for example gets struck by a foreign object, like a meteor. In that case, I’d like for both the terrain mesh AND its collider to be updated at runtime. It is absolutely critical for the design, to be able to locally regenerate the procedural terrain AND do it very fast (or async which is why I’m looking towards using Xenko instead of for example Unity)

So in other words, I want to update only some select single points on the collider

Attempts
Now I tried to fiddle a bit with Xenko’s code and I ended up with something like this:

var physicsComponent = this.Entity.Get<PhysicsComponent>();
var colliderShape = physicsComponent.ColliderShape();

Now at this point, I can’t directly access the points of the shape, so I’d have to use reflection which means that from your PoV, its not intended to be used like that, and besides - its a read only list, probably for the same reason:

Type tInfo = physicsComponent.ColliderShape.GetType();
var property = tInfo.GetRuntimeProperty("Points");
var points = property.GetValue(shape) as IReadOnlyList<Vector3>;

Questions
So on that note:

  1. Is it possible to partially update a complex mesh-based collider at runtime “the right way”?
  2. If not, will there be support for it in the near future?
2 Likes

It is possible, best is to:

  1. In a different thread create a new ConvexHullColliderShape, constructor takes a list of points and indices
  2. Replace the ColliderShape shape in the main thread of the PhysicsComponent
    You will have to use a place holder ColliderShape for the PhysicsComponent.

Can also use the experimental untested HeightfieldColliderShape

2 Likes

Wow this was far simpler than I anticipated! How fantastic! thank you :smiley: Going to experiment with some async regeneration now and hopefully I’ll get to a useable result :slight_smile: I’m excited to see how it performs asynchronously on large meshes

2 Likes