Raycast (interactable) seems somewhat inaccurate, what I'm doing wrong?

CoffeeOD

New member
Video:

As you can see, raycast seems to stay active outside object, in this example just the door, boundaries, especially vertical direction (up, down). Colliders and mesh itself should be fine since this was working with my own simple raycast script (tag based).

Any idea how I can tweak raycast to be more precise? We have small items hidden between/under other objects, so this would be quite a problem if raycast detection is not accurate.
 
What are the settings on your Interact ability? If you check Use Look Position and Use Look Direction and set Cast Offset to [0, 0, 0], then the source and direction of the ray will be exactly aligned with the character's look source:

1598005935492.png

If it's not that, maybe your character's look source is off? Try adding a Debug.DrawRay into DetectObjectAbilityBase.CanStartAbility to see the exact ray that's being cast in the scene:

C#:
        public override bool CanStartAbility()
        {
            ...

            // Use a raycast to detect if the character is near the object.
            if ((m_ObjectDetection & ObjectDetectionMode.Raycast) != 0) {
                // NEW LINE HERE v
                Debug.DrawRay(castTransform.TransformPoint(m_CastOffset), castDirection.normalized * m_CastDistance, Color.red);
                // NEW LINE HERE ^
                if (Physics.Raycast(castTransform.TransformPoint(m_CastOffset), castDirection, out m_RaycastResult, m_CastDistance, m_DetectLayers, m_TriggerInteraction)) {
                    var hitObject = m_RaycastResult.collider.gameObject;
                    if (ValidateObject(hitObject, m_RaycastResult)) {
                        m_DetectedObject = hitObject;
                        return true;
                    }
                }
            }
            
            ...
        }
 
Top