Hello,
I have what I assume is a very trivial problem but I cannot for the life of me figure it out. I am writing a simple fog of war system where the “fog” objects disappear when they enter the line of sight of a unit, represented by a Raycast
.
I have confirmed my line of sight Raycast
s are hitting the fog Collider
s. The OnTriggerEnter()
method of the fog class runs when it is hit by the unit’s BoxCollider
, but not it’s Raycast
.
The unit has a RigidBody
component and the fog BoxCollider
is set to "Is Trigger"
, and I’m not messing around with any layers.
If anyone has any idea what’s going on here please let me know.
Here are simple scripts for my fog and unit controllers:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FogTmp : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
Debug.Log("hit by: " + other.name);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnitTmp : MonoBehaviour
{
public float LoS = 12f;
private void FixedUpdate()
{
if (Physics.Raycast(transform.position + new Vector3(1.5f, 0, 0), transform.TransformDirection(Vector3.left), LoS))
{ Debug.Log("hitting!"); }
Debug.DrawRay(transform.position + new Vector3(1.5f, 0, 0), transform.TransformDirection(Vector3.left) * LoS, Color.green);
}
}