From b695b2f606b988903f3c39aaa49232a83c9b8b33 Mon Sep 17 00:00:00 2001 From: RaphaelIT7 <64648134+RaphaelIT7@users.noreply.github.com> Date: Wed, 26 Nov 2025 01:19:31 +0100 Subject: [PATCH] Fix elasticity not being clamped & try to reduce false collision detection for traces --- vphysics_jolt/vjolt_collide_trace.cpp | 3 ++- vphysics_jolt/vjolt_controller_player.cpp | 13 ++++--------- vphysics_jolt/vjolt_object.cpp | 6 +++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/vphysics_jolt/vjolt_collide_trace.cpp b/vphysics_jolt/vjolt_collide_trace.cpp index 30468b43..642ffe12 100644 --- a/vphysics_jolt/vjolt_collide_trace.cpp +++ b/vphysics_jolt/vjolt_collide_trace.cpp @@ -531,7 +531,8 @@ static void CastBoxVsShape( const Ray_t &ray, uint32 contentsMask, IConvexInfo * if ( vjolt_trace_castbox_backface_force.GetBool() ) settings.SetBackFaceMode( JPH::EBackFaceMode::CollideWithBackFaces ); settings.mCollisionTolerance = SourceToJolt::Distance( 0.1f * 0.25f ); // Regular VPhysics uses 0.25" here for the "collision tolerance"/epsilon, but when actually testing, it uses 0.1 * epsilon, so provide that here. - settings.mUseShrunkenShapeAndConvexRadius = true; + // RaphaelIT7: This was reported to cause possibly false collision detection, this probably is because this can result in more "rounded" shapes. + // settings.mUseShrunkenShapeAndConvexRadius = true; settings.mReturnDeepestPoint = false; ContentsFilter_Shape filter( pShape, contentsMask, pConvexInfo ); diff --git a/vphysics_jolt/vjolt_controller_player.cpp b/vphysics_jolt/vjolt_controller_player.cpp index 9b3a1c01..2f9f9ffb 100644 --- a/vphysics_jolt/vjolt_controller_player.cpp +++ b/vphysics_jolt/vjolt_controller_player.cpp @@ -457,19 +457,14 @@ void JoltPhysicsPlayerController::OnPostSimulate( float flDeltaTime ) Log_Msg( LOG_VJolt, "Player State:\n" " vOldPosition: %g %g %g\n" - " vOldVelocity: %g %g %g\n" " vNewPosition: %g %g %g\n" " vNewVelocity: %g %g %g\n" - " m_vLastImpulse: %g %g %g\n" - " vControllerVelocity: %g %g %g\n" - " vGroundVelocity: %g %g %g\n", - vOldPosition.x, vOldPosition.x, vOldPosition.z, - vOldVelocity.x, vOldVelocity.x, vOldVelocity.z, + " m_vLastImpulse: %g %g %g\n", + m_vOldPosition.x, m_vOldPosition.x, m_vOldPosition.z, vNewPosition.x, vNewPosition.x, vNewPosition.z, vNewVelocity.x, vNewVelocity.x, vNewVelocity.z, - m_vLastImpulse.x, m_vLastImpulse.x, m_vLastImpulse.z, - vControllerVelocity.x, vControllerVelocity.x, vControllerVelocity.z, - vGroundVelocity.x, vGroundVelocity.x, vGroundVelocity.z ); + m_vLastImpulse.x, m_vLastImpulse.x, m_vLastImpulse.z + ); #endif } diff --git a/vphysics_jolt/vjolt_object.cpp b/vphysics_jolt/vjolt_object.cpp index b9085ac8..831fcab2 100644 --- a/vphysics_jolt/vjolt_object.cpp +++ b/vphysics_jolt/vjolt_object.cpp @@ -1277,7 +1277,11 @@ void JoltPhysicsObject::UpdateMaterialProperties() { const surfacedata_t *pSurface = JoltPhysicsSurfaceProps::GetInstance().GetSurfaceData( m_materialIndex ); - m_pBody->SetRestitution( pSurface->physics.elasticity ); + // RaphaelIT7: idk why but Jolt loves to create a rocket if elasticity is too high. iirc IVP internally clamps this too between 0 and 1 - atleast I think I saw it do that somewhere? + // surface properties like Metal_bouncy have a ridiculous elasticity of 1000. + // Why exactly 3.75? because it seems to be the most realistic limit to still allow for super bouncy things. + // 0 to 1 does not mean 100% bouncy here, idk why SetRestitution has no documentation. + m_pBody->SetRestitution( Clamp(pSurface->physics.elasticity, 0, 3.75) ); m_pBody->SetFriction( pSurface->physics.friction ); m_flMaterialDensity = pSurface->physics.density; m_GameMaterial = pSurface->game.material;