diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index d3907b54..30e1a605 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -322,10 +322,14 @@ namespace Oyster inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float3 &j, const ::Oyster::Math::Float3 &at, const ::Oyster::Math::Float3 &normal ) { ::Oyster::Math::Float3 offset = at - this->centerPos; - ::Oyster::Math::Float3 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset ); - this->linearImpulse += j - ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset ); + if( offset.Dot(offset) > 0.0f ) + { + ::Oyster::Math::Float3 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset ); - this->angularImpulse += deltaAngularImpulse; + this->linearImpulse -= ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset ); + this->angularImpulse += deltaAngularImpulse; + } + this->linearImpulse += j; this->isDisturbed = true; } diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index 68f435e9..47a055e2 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -148,7 +148,12 @@ Float3 RigidBody::GetVelocity_Angular() const Float3 RigidBody::GetLinearMomentum( const Float3 &atWorldPos ) const { // by Dan Andersson - return this->momentum_Linear + Formula::TangentialLinearMomentum( this->momentum_Angular, atWorldPos - this->centerPos ); + Float3 offset = atWorldPos - this->centerPos; + if( offset.Dot(offset) > 0.0f ) + { + return this->momentum_Linear + Formula::TangentialLinearMomentum( this->momentum_Angular, offset ); + } + return this->momentum_Linear; } void RigidBody::SetMomentOfInertia_KeepVelocity( const MomentOfInertia &localTensorI )