I found that TrajectoryObjects were sometimes sticking to walls and over hangs. This mod will adjust the reflection velocity based on the vertical angle of the surface. This stops thrown items from attaching to surfaces they shouldn't.
Changed Class: TrajectoryObject.cs
Method: Move(ref Vector3 position, Quaternion rotation, bool simulation)
From:
To:
Changed Class: TrajectoryObject.cs
Method: Move(ref Vector3 position, Quaternion rotation, bool simulation)
From:
C#:
// The bounce strenght is dependent on the physic material.
var dynamicFrictionValue = m_Collider != null ? Mathf.Clamp01(1 - MathUtility.FrictionValue(m_Collider.material, m_RaycastHit.collider.material, true)) : 0f;
// Update the velocity to the reflection direction.
m_Velocity = dynamicFrictionValue * m_ReflectMultiplier * Vector3.Reflect(velocity, m_RaycastHit.normal);
To:
C#:
// The bounce strenght is dependent on the physic material.
var dynamicFrictionValue = m_Collider != null ? Mathf.Clamp01(1 - MathUtility.FrictionValue(m_Collider.material, m_RaycastHit.collider.material, true)) : 1f;
// adjust bounce for vertical surface
float maxBounce = Mathf.Max(m_ReflectMultiplier, 1f);
var verticalAngle = Vector3.Angle(m_RaycastHit.normal, Vector3.up);
var reflectionMultiplier = dynamicFrictionValue * m_ReflectMultiplier;
var bounceMultiplier = Mathf.Clamp(reflectionMultiplier + (maxBounce - reflectionMultiplier) * (verticalAngle / 180f), 0f, maxBounce);
// Update the velocity to the reflection direction.
m_Velocity = bounceMultiplier * Vector3.Reflect(velocity, m_RaycastHit.normal);
Last edited: