Model standing up after falling

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
mr_join
Posts: 14
Joined: Fri Nov 01, 2013 10:03 am

Model standing up after falling

Post by mr_join »

My physic object stand up after falling. Don't know how to fix it.
I'm used simple example for create boundObject from Mesh:

Code: Select all

Vector3[] vertices;
int[] indices;
List<Vector3> points = new List<Vector3>();
TriangleMesh.GetVerticesAndIndicesFromModel(boundModel, out vertices, out indices);

for (int i = 0; i < vertices.Length; i++)
{
      vertices[i] = vertices[i] * Scale;
}
points.AddRange(vertices);

_convexHull = new ConvexHull(points, 10);
points.Clear();

_convexHull.CollisionInformation.LocalPosition = _convexHull.Position;
_convexHull.Position = Position; //Position to Model Pos
 _convexHull.Orientation = Orientation; // Orientation to Model Orientation
and My Update Method is :

Code: Select all

_convexHull.Position += _gameObject.Dir_Move * _gameObject.Speed;
Vector3 speedRVect = new Vector3(_gameObject.Dir_Rot.X, _gameObject.Dir_Rot.Y, _gameObject.Dir_Rot.Z)
          * _gameObject.RotationSpeed; 
                   
Quaternion q = Quaternion.CreateFromYawPitchRoll(MathHelper.ToRadians(speedRVect.Y),
          MathHelper.ToRadians(speedRVect.X), MathHelper.ToRadians(speedRVect.Z));
                    
_convexHull.Orientation *= q;
 _gameObject.Position = _convexHull.Position;
_gameObject.Orientation = _convexHull.Orientation;
Aaaand the object makes the following items :
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Model standing up after falling

Post by Norbo »

_convexHull.CollisionInformation.LocalPosition = _convexHull.Position;
This offsets the collision shape from the center of mass, causing what you see. If LocalPosition is (0,0,0), the default, then the collision shape will be centered on the physical center of mass and rotation will look correct.

If your goal is to align the graphical model with the physical entity, I would recommend offsetting the graphical model.

If your goal is to make it easier to position objects by referring to the bottom of the chair instead of the center of mass, I would recommend storing the offset and using it to compute the center of mass's position as needed rather than trying to make the center of mass at the bottom of the chair.
_convexHull.Position += _gameObject.Dir_Move * _gameObject.Speed;
Vector3 speedRVect = new Vector3(_gameObject.Dir_Rot.X, _gameObject.Dir_Rot.Y, _gameObject.Dir_Rot.Z)
* _gameObject.RotationSpeed;

Quaternion q = Quaternion.CreateFromYawPitchRoll(MathHelper.ToRadians(speedRVect.Y),
MathHelper.ToRadians(speedRVect.X), MathHelper.ToRadians(speedRVect.Z));

_convexHull.Orientation *= q;
I'm not entirely clear on the goal of this code, but watch out: teleporting entities (setting position or orientation directly) is not a continuous physical action and will cause some problems.

Usually, it results in collisions appearing 'squishy' or otherwise wrong because the entities' velocities do not match their motion. The solver has nothing to work with.

To stop this from being an issue, control entities using forces and velocities instead of teleportation.
mr_join
Posts: 14
Joined: Fri Nov 01, 2013 10:03 am

Re: Model standing up after falling

Post by mr_join »

Thanks a lot! You very help me :)
Post Reply