Cheo
Active member
Hello, when subscribing to a collision event not related to ground collisions, there are significant chances that it is not executed, especially if the character is not moving fast. I also think that not using root motion can slightly increase the chances of the collision detection to malfunction. Here is a video as always to give a clear example :
And here is my test script :
Here are also the modifications I made to Character Locomotion - first add these properties :
And in Detect Collisions add this new event underneath the existing one :
Hope this can be reproduced and looked into, thanks.
And here is my test script :
C#:
using Opsive.Shared.StateSystem;
using Opsive.UltimateCharacterController.Character;
using UnityEngine;
public class CharacterCollisionEvent : StateBehavior
{
[SerializeField] protected bool m_CollisionEventEnabled = true;
public bool CollisionEventEnabled { get { return m_CollisionEventEnabled; } set { m_CollisionEventEnabled = value; } }
private CharacterLocomotion m_CharacterLocomotion;
protected override void Awake()
{
base.Awake();
m_CharacterLocomotion = GetComponentInParent<CharacterLocomotion>();
m_CharacterLocomotion.OnNonGroundCollision += (RaycastHit hit) =>
{
CollisionEvent(hit);
};
}
private void CollisionEvent(RaycastHit hit)
{
if (m_CollisionEventEnabled)
{
Debug.Log("CharacterCollisionEvent hit " + hit.collider.name);
}
}
private void OnDestroy()
{
m_CharacterLocomotion.OnNonGroundCollision -= (RaycastHit hit) =>
{
CollisionEvent(hit);
};
}
}
Here are also the modifications I made to Character Locomotion - first add these properties :
C#:
private Action<RaycastHit> m_OnNonGroundCollision;
[Shared.Utility.NonSerialized] public Action<RaycastHit> OnNonGroundCollision { get { return m_OnNonGroundCollision; } set { m_OnNonGroundCollision = value; } }
And in Detect Collisions add this new event underneath the existing one :
C#:
// Others may be interested in the collision.
if (m_OnCollision != null) {
m_OnCollision(closestRaycastHit);
}
if (m_OnNonGroundCollision != null)
{
m_OnNonGroundCollision(closestRaycastHit);
}
Hope this can be reproduced and looked into, thanks.