Cheo
Active member
Hello everyone and Merry Christmas ! Here is a cool modification for projectiles - by multiplying the Vector3 meant to be added to the projectile's position when hitting and sticking to an object, it is possible to make it push further into the hit object. I made this because so far when arrows hit an enemy's ragdoll colliders, they didn't look like they were actually penetrating the limbs, whereas with this modification enemies look like Sean Bean at the end of The Fellowship of the Ring !
This is quite straightforward, first add this float parameter to ProjectileBase :
Then in OnCollision, add this : (lines above are for reference)
Lastly this can be added at the end of ProjectileBaseInspector.DrawObjectFields :
I hope you find this as satisfying as I do ! @Justin lemme know if you think this is worth adding to the code.
This is quite straightforward, first add this float parameter to ProjectileBase :
C#:
[SerializeField] protected float m_PenetrationMovementMultiplier = 1f;
public float PenetrationMovementMultiplier { get { return m_PenetrationMovementMultiplier; } set { m_PenetrationMovementMultiplier = value; } }
Then in OnCollision, add this : (lines above are for reference)
C#:
var forceDestruct = false;
if (m_CollisionMode == CollisionMode.Collide) {
// When there is a collision the object should move to the position that was hit so if it's not destroyed then it looks like it
// is penetrating the hit object.
if (hit != null && hit.HasValue && m_Collider != null) {
if (!m_DestroyOnCollision) {
var closestPoint = m_Collider.ClosestPointOnBounds(hit.Value.point);
m_Transform.position += (hit.Value.point - closestPoint) * m_PenetrationMovementMultiplier;
}
Lastly this can be added at the end of ProjectileBaseInspector.DrawObjectFields :
C#:
PropertiesFoldout(container, "Custom", m_ExcludeFields, new[]
{
"m_PenetrationMovementMultiplier"
});
I hope you find this as satisfying as I do ! @Justin lemme know if you think this is worth adding to the code.