Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Engine/source/T3D/rigid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ void Rigid::integrate(F32 delta)

}

void Rigid::preIntegrateForces(F32 delta)
{
// Update momentum and velocity, but don't integrate forward in time (don't move the object).
// This makes sure the current tick's changes in velocity, for example from gravity, are visible to the collision solver for this tick
angMomentum = angMomentum + torque * delta;
linMomentum = linMomentum + force * delta;
updateVelocity();
// This should only be called when paired with a follow-up call to integrate with the same delta,
// generally after collision and clearing the forces again
}

void Rigid::updateVelocity()
{
linVelocity.x = linMomentum.x * oneOverMass;
Expand Down
1 change: 1 addition & 0 deletions Engine/source/T3D/rigid.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Rigid
//
Rigid();
void clearForces();
void preIntegrateForces(F32 delta);
void integrate(F32 delta);

void updateInertialTensor();
Expand Down
29 changes: 14 additions & 15 deletions Engine/source/T3D/rigidShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ RigidShapeData::RigidShapeData()

minDrag = 0;
maxDrag = 0;
integration = 1;
integration = 4;
collisionTol = 0.1f;
contactTol = 0.1f;
massCenter.set(0,0,0);
Expand Down Expand Up @@ -874,7 +874,7 @@ void RigidShape::processTick(const Move* move)
mDelta.rot[0] = mRigid.angPosition;

// Update the physics based on the integration rate
S32 count = mDataBlock->integration;
S32 count = mDataBlock->integration + (S32)(getVelocity().lenSquared()/TickMs);
--mWorkingQueryBoxCountDown;

if (!mDisableMove)
Expand Down Expand Up @@ -1156,6 +1156,9 @@ void RigidShape::updatePos(F32 dt)
bool collided = false;
if (!mRigid.atRest && !mDisableMove)
{
mRigid.preIntegrateForces(dt);
mRigid.clearForces();

collided = updateCollision(dt);

// Now that all the forces have been processed, lets
Expand Down Expand Up @@ -1627,12 +1630,10 @@ U32 RigidShape::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
stream->writeFlag(mask & ForceMoveMask);

stream->writeCompressedPoint(mRigid.linPosition);
if (!stream->writeFlag(mRigid.atRest))
{
mathWrite(*stream, mRigid.angPosition);
mathWrite(*stream, mRigid.linMomentum);
mathWrite(*stream, mRigid.angMomentum);
}
stream->writeFlag(mRigid.atRest);
mathWrite(*stream, mRigid.angPosition);
mathWrite(*stream, mRigid.linMomentum);
mathWrite(*stream, mRigid.angMomentum);
}

if(stream->writeFlag(mask & FreezeMask))
Expand Down Expand Up @@ -1667,13 +1668,11 @@ void RigidShape::unpackUpdate(NetConnection *con, BitStream *stream)
{
mRigid.setAtRest();
}
else
{
mathRead(*stream, &mRigid.angPosition);
mathRead(*stream, &mRigid.linMomentum);
mathRead(*stream, &mRigid.angMomentum);
mRigid.updateVelocity();
}

mathRead(*stream, &mRigid.angPosition);
mathRead(*stream, &mRigid.linMomentum);
mathRead(*stream, &mRigid.angMomentum);
mRigid.updateVelocity();

if (!forceUpdate && isProperlyAdded())
{
Expand Down
5 changes: 4 additions & 1 deletion Engine/source/T3D/vehicles/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void Vehicle::processTick(const Move* move)
mDelta.rot[0] = mRigid.angPosition;

// Update the physics based on the integration rate
S32 count = mDataBlock->integration;
S32 count = mDataBlock->integration + (S32)(getVelocity().lenSquared() / TickMs);
--mWorkingQueryBoxCountDown;

if (!mDisableMove)
Expand Down Expand Up @@ -816,6 +816,9 @@ void Vehicle::updatePos(F32 dt)
bool collided = false;
if (!mRigid.atRest && !mDisableMove)
{
mRigid.preIntegrateForces(dt);
mRigid.clearForces();

collided = updateCollision(dt);

// Now that all the forces have been processed, lets
Expand Down
Loading