I have a Player prefab with a Character Controller component that when it overlaps the trigger for a pressure plate, the OnTriggerEnter method is called. However, I also have a Sheep prefab with a Character Controller component that does not call the OnTriggerEnter method though it did yesterday (despite not changing any properties for this pressure plate or Sheep’s triggers script).
I’m at a total loss as I have tried everything from ensuring the method declaration is spelled correctly
private void OnTriggerEnter(Collider other)
to making sure the “isTrigger” box is ticked for the BoxCollider on the pressure plate. I also tried adding a RigidBody that is kinematic to the Sheep prefab and then to the Pressure Plate prefab but to no avail. Any help would be greatly appreciated.
Sheep Prefab:
The Sheep prefab has just a CharacterController with the exact same property settings as the Player prefab other than the height. As I understand it, the CharacterController component has a RigidBody so I don’t need to add one for the collision system to work (as I have done with the Player).
Pressure Plate Prefab:
Each Cube on the Pressure Plate including the base has a BoxCollider with “isTrigger” unticked. Only the Trigger child GameObject has a BoxCollider with “isTrigger” ticked.
PlayerTriggers.cs (attached to Player)
public class PlayerTriggers : MonoBehaviour
{
PlayerMovement movement;
private void Awake()
{
movement = GetComponent<PlayerMovement>();
}
private void Start()
{
Physics.IgnoreLayerCollision(gameObject.layer, Layers.SHEEP);
}
private void OnTriggerEnter(Collider other)
{
print("PLAYER ON TRIGGER ENTER------------------------");
if (other.CompareTag(Tags.SPRING))
{
movement.Spring(other.GetComponent<Spring>().GetForce());
}
}
}
SheepTriggers.cs (attached to Sheep):
public class SheepTriggers : MonoBehaviour
{
private SheepMovement movement;
private void Awake()
{
movement = GetComponent<SheepMovement>();
}
void OnTriggerEnter(Collider other)
{
print("TRIGGER---------------------------");
if (other.CompareTag(Tags.SPRING))
{
movement.Spring(other.GetComponent<Spring>().GetForce());
}
if (other.CompareTag(Tags.PRESSURE_PLATE))
{
movement.SetIdle(true);
}
if (other.CompareTag(Tags.CONVEYOR_BELT))
{
movement.AddVelocity(other.GetComponent<ConveyorBelt>().GetVelocity());
}
}
}
When the Player moves onto the Pressure Plate, the debug console prints PLAYER ON TRIGGER ENTER------------------------
, but for the Sheep it prints nothing. Any ideas? Is there something I’m missing here? Thanks so much!