I create space-sim game and have some problems with correct implementation of BEPU. I have some object categories:
- player - we are inside cockpit and can move in all directions
- friendly / enemy ship - can move in all directions
- static objects like asteroids - they don't move
- bullets - move forward
- missiles - move like ships
For all of them I use Entity to represent physics. Is it good for player / ships to use Entity, or maybe I should change it to CharacterController ?
In update method I calculate current speed (on my own) and after that I set Velocity:
Code: Select all
movement = new Vector3(0, 0, CurrentSpeed);
movement = Vector3.Transform(movement, Rotation); // movement vector
Physics.LinearVelocity = Game1.ConvertVector3ToBEPU(movement); // (1)
//Physics.LinearVelocity = Game1.ConvertVector3ToBEPU(movement * dTime * Game1.SpeedMultiply); // (2)
When I using (1) my game slow down when have low FPS (some kind like slow motion).
When I using (2) my game work properly but Physics.LinearVelocity are different every frame and my ship, or friendly / enemy ship are shaking.
My space update method look like:
Code: Select all
private void UpdateSpace()
{
space.ForceUpdater.Update();
space.BoundingBoxUpdater.Update();
space.BroadPhase.Update();
space.DeferredEventDispatcher.Update();
space.NarrowPhase.Update();
space.PositionUpdater.Update();
space.BeforeNarrowPhaseUpdateables.Update();
space.BeforePositionUpdateUpdateables.Update();
space.BeforeSolverUpdateables.Update();
space.DeactivationManager.Update();
space.DuringForcesUpdateables.Update();
space.EndOfFrameUpdateables.Update();
space.EndOfTimeStepUpdateables.Update();
space.EntityStateWriteBuffer.Update();
space.Solver.Update();
}