I want to update a single entity (a character), pushing it around the Space per normal, except completely off the main update loop.
Now, there are two ways to go about this:
1, the slow and boring way: Freeze everything, update the Space, unfreeze everything. That's not right.
2, the fast and fun way: Manually call everything I need to call to make the object fly forth. That's more my level of sanity.
So, this is what I've gotten so far:
(CBody is a CharacterController)
(TheRegion.PhysicsWorld is my ridiculously named Space object)
Code: Select all
((IBeforeSolverUpdateable)CBody).Update(tstep);
CBody.HorizontalMotionConstraint.Update(tstep);
CBody.VerticalMotionConstraint.Update(tstep);
((IForceUpdateable)CBody.Body).UpdateForForces(tstep);
CBody.Body.CollisionInformation.UpdateBoundingBox(tstep);
((IBroadPhaseEntryOwner)CBody.Body).Entry.UpdateBoundingBox();
List<BroadPhaseEntry> bpes = new List<BroadPhaseEntry>();
TheRegion.PhysicsWorld.BroadPhase.QueryAccelerator.GetEntries(CBody.Body.CollisionInformation.BoundingBox, bpes);
foreach (BroadPhaseEntry bpe in bpes)
{
if (CBody.Body.CollisionInformation != bpe && TheRegion.PhysicsWorld.NarrowPhase.GetPair(CBody.Body.CollisionInformation, bpe) == null)
{
NarrowPhasePair npp = NarrowPhaseHelper.GetPairHandler(CBody.Body.CollisionInformation, bpe);
TheRegion.PhysicsWorld.NarrowPhase.OnCreatePair(npp); // I may have edited BEPU's source to expose this method, don't hate me, I needed it for a thing.
}
}
foreach (CollidablePairHandler entry in CBody.Body.CollisionInformation.Pairs)
{
entry.UpdateCollision(tstep);
entry.UpdateTimeOfImpact(CBody.Body.CollisionInformation, tstep);
}
((ICCDPositionUpdateable)CBody.Body).PreUpdatePosition(tstep);
((ICCDPositionUpdateable)CBody.Body).UpdateTimesOfImpact(tstep);
((ICCDPositionUpdateable)CBody.Body).UpdatePositionContinuously(tstep);
So now I realize at some point I'm going to have to explain why I'm doing this...
This is actually a common thing to do when not using a physics engine. (And sometimes /with/ one, in cases like the Source engine!) It's a key point in properly transmitting a player's own movement across a network laglessly with client-side prediction. You have to move the player off-tick clientside to make it move to the correct location it belongs at.
So what's the problem with my code? MANY THINGS. But the problem I came here for specifically: The body will slowly fall into the ground, jump back up (as per the server's orders), then fall back in. It does so very slowly, very slightly, just enough to barely notice. I can almost ignore it and focus on more important things, but that'll rapidly get annoying with time.
Also the surrounding code doesn't seem to work much but that's my own problem, no need to worry you about it. I just want to get the player not having its feet inside the ground before I continue patching that up.