StaticMesh and Kinematics

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
jimmyfo
Posts: 12
Joined: Sun Dec 25, 2011 7:27 pm

StaticMesh and Kinematics

Post by jimmyfo »

Hi there, two separate questions on two separate types of objects :)

1) In my current test, I have a few entities and a large static mesh added to my game space. I can easily draw the bounding box of all the entities using something like this:

Code: Select all

        for (int i = 0; i < gameSpace.Entities.Count; i++)
        {
            DebugShapeRenderer.AddBoundingBox(gameSpace.Entities[i].CollisionInformation.BoundingBox, Color.Red);
        }
        DebugShapeRenderer.Draw(new GameTime(), FPSCamera.ViewMatrix, FPSCamera.ProjectionMatrix);
However, I didn't realize that static meshes are not considered "entities" per se, and so there bounding boxes are not being drawn. If I store a list of StaticMeshes added to my game, I can reference them for my debug renderer and draw there using something like "staticMeshes.BoundingBox", but I'd rather just call the Bepu gamespace. Is that possible?
2) Looking through the demos and forum posts on kinematic (searched by "kinematic," npc was to short to search by :) ), I see a number of options. A lot of them are based around using EntityMovers of some sort, and applying TargetPosition/TargetOrientation (to avoid teleportation). In the case of an NPC, I would like to give them the ability to move around based on a random path - I would also like them to never "leave the ground," so to say - for example, if the ground goes up and down, I would basically like to define their paths in an X/Z direction, and have them fall/rise to the appropriate Y level as the ground dictates. Is there an easy way to do this, or would this be based on extending the CharacterController class, without the input?
2a) What is the best way to make a moving entity (as above) with a convex hull as the model? The mobile mesh demo looked close, but does not have "Entity" anywhere I can understand it :)

Thanks,
James
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: StaticMesh and Kinematics

Post by Norbo »

If I store a list of StaticMeshes added to my game, I can reference them for my debug renderer and draw there using something like "staticMeshes.BoundingBox", but I'd rather just call the Bepu gamespace. Is that possible?

The Space does not keep an explicit list of all BroadPhaseEntry objects (things which have BoundingBoxes, which include StaticMeshes) around since such a list would never be used internally. Instead, they are just held directly within the broad phase's internal structure. That structure isn't generally amenable to iteration. So, for this sort of thing, I would recommend just using an explicit external list.

2) Looking through the demos and forum posts on kinematic (searched by "kinematic," npc was to short to search by ), I see a number of options. A lot of them are based around using EntityMovers of some sort, and applying TargetPosition/TargetOrientation (to avoid teleportation). In the case of an NPC, I would like to give them the ability to move around based on a random path - I would also like them to never "leave the ground," so to say - for example, if the ground goes up and down, I would basically like to define their paths in an X/Z direction, and have them fall/rise to the appropriate Y level as the ground dictates. Is there an easy way to do this, or would this be based on extending the CharacterController class, without the input?

The defining feature of a kinematic entity is that it has effectively infinite inertia and does not respond to forces of any kind. It just plows forward with whatever velocity it is given. This isn't usually suitable for characters.

If you want your NPC to react to the environment somehow, it should probably be a dynamic entity. CharacterControllers, which use a dynamic entity, would indeed be a good option here; it does not sound like it needs any extension to do what you need. Check out the CharacterStressTestDemo for an example of a bunch of CharacterControllers being managed directly without any user input.

2a) What is the best way to make a moving entity (as above) with a convex hull as the model? The mobile mesh demo looked close, but does not have "Entity" anywhere I can understand it

The MobileMesh itself is an Entity. MobileMesh, Box, Sphere, ConvexHull, and the others are the 'prefab' entity types that manage the creation of the shape and collidable for you. They're there primarily for legacy and convenience reasons.

The CharacterController itself uses a cylinder because it's rotationally invariant around its up axis (and a few other reasons). Convex hulls and meshes are not, in general, rotationally invariant at all. A character that needs to actually spin its shape to turn will run into all sorts of problems when it gets obstructed.

If those obstruction behaviors are desired, you could do something like controlling the dynamic entity's orientation with a SingleEntityAngularMotor. The entity would then bump into walls as it tries to turn and respond somewhat appropriately. Of course, if the object gets itself spinning real fast, then it would be easy enough to launch high into the sky.

Another option would be to avoid the constraint and just set the entity's local inverse inertia tensor to the zero matrix to prevent it from falling over. Then, just set its orientation directly to whatever you want (watch out, this is a form of teleporation and will hurt collision response!), or set the angular velocity to turn (potential for launching once again).

Once you have the angular motion handled, then you can just shove the 'character' around by changing its linear velocity or whatever else. A lot of work went into making the CharacterController robust, though; if you want character-like behaviors, I would recommend just sticking to the CharacterController.
jimmyfo
Posts: 12
Joined: Sun Dec 25, 2011 7:27 pm

Re: StaticMesh and Kinematics

Post by jimmyfo »

Great post describing great code. Thanks! And donated.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: StaticMesh and Kinematics

Post by Norbo »

Great post describing great code. Thanks! And donated.
Thanks very much, and you're welcome :)
Post Reply