I’m attempting to send a ray from a little box, Object A, to another object that has a trigger collider. That other object, Object B, has a script that is basically “OnTriggerEnter” with a debug notification. I know the ray is hitting object B because it tells me it’s distance from the object and the layermask can only hit that one object.
I’ve eliminated so many variables that I really don’t know what I could have done wrong. Any help would be greatly appreciated.
Object A
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Object_Physics : MonoBehaviour
{
// Start is called before the first frame update
public int maxDistance = 50;
//The maximum distance at which the object can be detected
public double rayDistanceObj = 0;
//tracks the distance between both objects
void FixedUpdate()
{
int layerMask = 1 << 9;
//Detects only the Mask I choose
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, maxDistance, layerMask, QueryTriggerInteraction.Collide)){
rayDistanceObj = hit.distance;
}
}
}
`
Object B
using System.Collections.Generic;
using UnityEngine;
public class SC_RigidbodyMagnet : MonoBehaviour
{
void FixedUpdate()
{
}
void OnTriggerEnter(Collider other)
{
Debug.Log("Object triggered");
}
void OnTriggerExit(Collider other)
{
}
}