EntityMover

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

EntityMover

Post by jimmyfo »

Hi, just a few questions trying to understand how this works :)

1) In my world space, the vast majority of my models use StaticMesh. There are a few models I want to move by setting their position manually (i.e. teleportation, as you call it) during gameplay, and for them, I chose to use a predefined cylinder mesh movingEntity with the EntityMover class. I'm not looking at the code right now, but I believe the call to place it is something like TargetPosition. A few questions on that:
a) Since a static mesh world matrix/position can be set manually anytime after initialization, is there a reason to use an EntityMover as opposed to StaticMesh?
b) On accident, I found that two cylinders defined in that method with the EXACT same position/scale/etc, it is very easy to get a NaN exception thrown within the cylinder code. Is there a reason for that?
c) When, using the CharacterController, I walk into these cylinders, and am obstructed - correct behaviour. However, it often happens that after I walk into them, a short while (.1 to .5 seconds later), I am "bumped" away from the cylinder I walked into - it is almost like I intersected into the model, or the model moved when I walked into it and then reset into place. Are these occuring? I do not experience this behaviour with static meshes.

2) This is no longer an issue, but is easily repeatable, if you're interested: if I manually change the orientation of the cylinder in the CharacterController body and then go to an area that does not have support underneath but where the model does not fall through (say, a very small gap between two objects with no support underneath, or hanging off an edge of a model), a NaN exception occurs in the cylinder update function. I fixed this by realizing there was no reason to change the orientation of a cylinder, but this is just FYI.

Thanks for the help and the fabulous product!
James
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: EntityMover

Post by Norbo »

a) Since a static mesh world matrix/position can be set manually anytime after initialization, is there a reason to use an EntityMover as opposed to StaticMesh?
Note that the EntityMover does not teleport objects by setting their Position. It uses a motor for dynamic objects and directly controls velocities for kinematic objects. Entities controlled by the EntityMover convenience class will undergo correct collision response. (Of course, kinematic entities moved an extremely long distance in one frame by velocity alone will have extremely high velocities, so having a correct collision response might not be desired!)

StaticMeshes are also slower than entities at moving. It has to refit its entire hierarchy for collisions to work properly at the new state. An Entity using a MobileMeshShape, on the other hand, has a local space acceleration structure which does not need to be updated. If the objects move every frame, an Entity using a MobileMeshShape is more efficient than a StaticMesh. If the object is only moved every once in a while, using a StaticMesh probably wins overall (as long as the refit cost is low enough to run on the fly).
b) On accident, I found that two cylinders defined in that method with the EXACT same position/scale/etc, it is very easy to get a NaN exception thrown within the cylinder code. Is there a reason for that?
Is that in v1.2 (the development version)? A quick attempt to reproduce the problem failed. If you could reproduce it in a demo in the development version of the BEPUphysicsDemos for me to debug, that would be helpful.
c) When, using the CharacterController, I walk into these cylinders, and am obstructed - correct behaviour. However, it often happens that after I walk into them, a short while (.1 to .5 seconds later), I am "bumped" away from the cylinder I walked into - it is almost like I intersected into the model, or the model moved when I walked into it and then reset into place. Are these occuring? I do not experience this behaviour with static meshes.
That is not expected behavior. Could you reproduce it in a development version demo?

My only current guess would be some scale related issue; if the scale is handled inconsistently, there might be some tuning factor somewhere which doesn't quite line up.
2) This is no longer an issue, but is easily repeatable, if you're interested: if I manually change the orientation of the cylinder in the CharacterController body and then go to an area that does not have support underneath but where the model does not fall through (say, a very small gap between two objects with no support underneath, or hanging off an edge of a model), a NaN exception occurs in the cylinder update function. I fixed this by realizing there was no reason to change the orientation of a cylinder, but this is just FYI.
While changing the orientation of the CharacterController body is not directly supported and can definitely cause some problems unless everything is handled carefully, my attempt to reproduce this in the development version also failed.

If the failure you saw was extremely reproducible and common with any change of the orientation, it may have been a hint at another problem. If this still happens with the development version of the character and engine, it might be worth investigating further (and a reproduction demo would be nice in this case :)).
Thanks for the help and the fabulous product!
James
Thanks and you're welcome :)
jimmyfo
Posts: 12
Joined: Sun Dec 25, 2011 7:27 pm

Re: EntityMover

Post by jimmyfo »

I was using 1.1, wasn't aware of 1.2! Just downloaded, will build and include in my project, and see about recreating these issues today (all three: CharacterController cyclinder rotation, overlapping EntityMovers, and being "bumped" away from movers).

Thanks for the explanations! So an EntityMover would be used for a game object that moves, but can be pushed off it's path? Does it always try to return to the defined path if pushed off? Does the mass of, say, the CharacterController affect how the EntityMover interacts with the character cylinder? I noticed in the mobile mesh that a mass can be defined - does this allow a mobile mesh to be moved via game interactions? That said, replacing my EntityMovers with MobileMeshes has stopped the errors I encountered (so far).

Will keep you posted on the testing.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: EntityMover

Post by Norbo »

So an EntityMover would be used for a game object that moves, but can be pushed off it's path? Does it always try to return to the defined path if pushed off?
An EntityMover acting on a dynamic entity is just a convenience class which wraps a SingleEntityLinearMotor. When a target position is specified, the motor attempts to reach that position. If an incoming force is sufficiently strong to overpower the motor, the object can be pushed away from its current goal. If that force stops, the motor will once again pull it towards the goal. The motor's spring settings are configurable. Note that the EntityMover has no concept of paths, just target positions.

An EntityMover acting upon a kinematic entity cannot be stopped because kinematic entities cannot be stopped. They will crush and fly through anything without stopping. Dynamic entities in the way of a kinematic entity have to move out of the way.
Does the mass of, say, the CharacterController affect how the EntityMover interacts with the character cylinder?
Yes, if the EntityMover is moving a dynamic entity. The motor isn't infinitely strong, so a sufficiently heavy object will resist it.
I noticed in the mobile mesh that a mass can be defined - does this allow a mobile mesh to be moved via game interactions?
Yes, the MobileMesh is an Entity that uses a MobileMeshShape in the same way that an Entity can use a BoxShape. (The Box and MobileMesh classes are just convenience classes that set up the entity's collidable and shape automatically, which you could do manually if you wanted.) Making the mobile mesh dynamic allows it to behave like any other dynamic entity.

However, it is always recommended that approximations are used when possible. If it could be represented by a few boxes or convex hulls instead of a few hundred triangles, it would be a good idea to go with the approximation. For the cases where approximations aren't reasonable, mobile meshes are a good way to go.
Post Reply