Bepu v1 update entity position without update space?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
starlaoxmelgs
Posts: 15
Joined: Mon Jan 13, 2020 8:26 am

Bepu v1 update entity position without update space?

Post by starlaoxmelgs »

Image
Calling Space.Update() is too slow, maybe it's because scene mesh has 3934 faces.
My game not really need to update space.
It has one scene and some players, I have already implemented collision limit using ConvexCast before, find contact point, and limit player's position.
Players are always moving, so when players move, I need to update theirs entity position, so RayCast and ConvexCast can hit them.
Problem is that when I update entity's position,its position data really changed, but its collision data doesn't seems like, RayCast still can't hit it.

Code: Select all

Box playerEntity = new Box(new BEPUutilities.Vector3(999, 999, 999), 1, 1, 1, 1);
space.Add(playerEntity);
playerEntity.Position = new BEPUutilities.Vector3(0, 0, 0);

RayCastResult rayCastResult;
BEPUutilities.Ray ray = new BEPUutilities.Ray();
ray.Position = new BEPUutilities.Vector3(0, 10, 0);
ray.Direction = BEPUutilities.Vector3.Down;
float distance = 1000;

if (space.RayCast(ray, distance, out rayCastResult))
{
}
else
{
    //Not Hit
}
Code above can not hit player as it should.
But If I update space, it will work.

Code: Select all

Box playerEntity = new Box(new BEPUutilities.Vector3(999, 999, 999), 1, 1, 1, 1);
space.Add(playerEntity);
playerEntity.Position = new BEPUutilities.Vector3(0, 0, 0);
space.Update(0.1f);

RayCastResult rayCastResult;
BEPUutilities.Ray ray = new BEPUutilities.Ray();
ray.Position = new BEPUutilities.Vector3(0, 10, 0);
ray.Direction = BEPUutilities.Vector3.Down;
float distance = 1000;

if (space.RayCast(ray, distance, out rayCastResult))
{
    //Hit
}
else
{
}
Is there any way to update entity's position without Space.Update()?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu v1 update entity position without update space?

Post by Norbo »

Space-wide queries rely on the broad phase. Setting a position will not update the broad phase's data structures directly.

After updating positions, you'll need to update the collidable's bounding box (entity.CollisionInformation.UpdateBoundingBox) and then update the broad phase (Space.BroadPhase.Update).

That said, something is badly wrong. Unless you have tens of thousands of objects interacting with each other, even v1 shouldn't be showing 150ms update times. From what you described, it sounds like you have some players and a mesh. That should take <1ms on a single thread.
starlaoxmelgs
Posts: 15
Joined: Mon Jan 13, 2020 8:26 am

Re: Bepu v1 update entity position without update space?

Post by starlaoxmelgs »

Thanks :D
Yes, I am confused about 150ms too.
I am not familiar with v1, is there anything strange in the profile screenshot? (Too many calls? unusual method execution time?)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Bepu v1 update entity position without update space?

Post by Norbo »

I am not familiar with v1, is there anything strange in the profile screenshot? (Too many calls? unusual method execution time?)
Nothing specific- all of the times are just way too high.

The mesh-convex pair is taking 146ms for 30 calls, or almost 5ms per mesh-convex test. Under normal circumstances, that would suggest tens of thousands of children pair being tested in each mesh-convex pair, but there are only 429 triangle-convex subpairs called. That's about 14 triangles tested per mesh-convex pair, which is pretty reasonable.

It is notable that so many of those tests are resorting to deep contact, which is more expensive than shallow contact- that would imply a bunch of objects are embedded in the mesh. But deep penetration is only maybe 3x more expensive than shallow touching, not 1000x.

Best guess would be some environmental factor. Running in the unity editor in debug configuration, for example, definitely comes with a cost. Not sure if that is enough to explain it, but it's part of it. Could be some wonkiness with the runtime too, though v1 doesn't use anything fancy like v2 so it should be fine in that regard.
starlaoxmelgs
Posts: 15
Joined: Mon Jan 13, 2020 8:26 am

Re: Bepu v1 update entity position without update space?

Post by starlaoxmelgs »

Thanks :D
Need to look at environmental settings.
Post Reply