This is the first physics engine for me and I've learned a lot by reading this forum so thanks to you and all the questions and answers
But now I have no idea how to fix my problem. I'm using Bepu v1.3.0 and its slightly modified "GettingStartedDemo". This is my test project to test this issue but the same problem occurs on my real project.
I have a scaled box of type StaticMesh as flat platform, on which I move my dynamic Box entity (I'll call this "dude" from now on). Gravity is on all the time and dude's LocalInertiaTensorInverse is set to zero. Now, if I move "dude" around on an edge or any corner of the platform, dude jumps occasionally (Y changes by like 0,4-1,8 units). Feels like it happens more often when dude goes from flat area toward edge/corner... Also rotating dude on a corner causes sometimes strange movement on X and Z axis of LinearVelocity but not Y. But funny thing is that I couldn't reproduce this issue if the platform is massless (kinematic?) Box. I move THE Dude with LinearVelocity and AngularVelocity (I've tried EntityRotator and EntityMover but I'd like to do it on my own to understand things better). Strange part is that I'm trying to avoid changing LinearVelocity.Y to let gravity pull entities but it still changes and I've been thinking it's gravity somehow? But I would LOVE to know why this happens and how to fix it properly without hacky ways
This is how I move THE Dude:
Code: Select all
if (KeyboardState.IsKeyDown(Keys.G))
{
controlledDude.AngularVelocity += Vector3.Up / 1.5f;
}
if (KeyboardState.IsKeyDown(Keys.J))
{
controlledDude.AngularVelocity += Vector3.Down / 1.5f;
}
if (KeyboardState.IsKeyDown(Keys.Y))
{
controlledDude.LinearVelocity += new Vector3(controlledDude.OrientationMatrix.Forward.X * 1.5f, 0, controlledDude.OrientationMatrix.Forward.Z * 1.5f);
}
if (KeyboardState.IsKeyDown(Keys.H))
{
controlledDude.LinearVelocity += new Vector3(controlledDude.OrientationMatrix.Backward.X * 1.5f, 0, controlledDude.OrientationMatrix.Backward.Z * 1.5f);
}
Code: Select all
void SlowDownEntity(Entity e)
{
if (e.LinearVelocity.Length() > .01f)
{
Vector3 velocity = e.LinearVelocity;
// Reduce X and set to zero if it's slow enough
float xDot = Vector3.Dot(Vector3.UnitX, velocity);
Vector3 xDiff = Vector3.Zero;
Vector3 reduce = new Vector3(velocity.X * .2f, 0, 0);
Vector3 xVelocity = new Vector3(velocity.X, 0, 0);
Vector3.Subtract(ref xVelocity, ref reduce, out xDiff);
if (Math.Abs(xDot) < .2f)
velocity.X = 0;
// Same thing for Z
float zDot = Vector3.Dot(Vector3.UnitZ, velocity);
Vector3 zDiff = Vector3.Zero;
reduce = new Vector3(0, 0, velocity.Z * .2f);
Vector3 zVelocity = new Vector3(0, 0, velocity.Z);
Vector3.Subtract(ref zVelocity, ref reduce, out zDiff);
if (Math.Abs(zDot) < .2f)
velocity.Z = 0;
velocity.X = xDiff.X;
velocity.Z = zDiff.Z;
e.LinearVelocity = velocity;
}
}
Code: Select all
void RemoveFriction(EntityCollidable sender, BroadPhaseEntry other, NarrowPhasePair pair)
{
var collidablePair = pair as CollidablePairHandler;
if (collidablePair != null)
{
collidablePair.UpdateMaterialProperties(new InteractionProperties());
}
}