Can't get colliders/triggers to work with NPCsSolved
Hi,
I'm trying to use Colliders to create triggers with MonoBehaviour, like how K1llyou's Zones plugin does it. The problem is that the triggers don't seem to be... triggering when an npc enters them, only when an entity does. I've tested with the ScrapTransportHelicopter, all sorts of twig building blocks, my player, and scientists.

Here's the "Trigger" class I'm using, basically a cut down version of K1llyou's "Zone" class.

public class Trigger : MonoBehaviour
{
Game game;
internal Collider collider;
internal Bounds bounds;
private Rigidbody rigidbody;

private void OnTriggerEnter(Collider collider)
{
BaseEntity baseEntity = collider?.ToBaseEntity();
if (!baseEntity.IsValid()) return;
if (baseEntity is BasePlayer)
{
foreach (var person in BasePlayer.activePlayerList)
{
//Since I can't use puts since it's non-static or something, I use this.
person.ChatMessage("Test" + collider.gameObject.name);
}
}
foreach (var person in BasePlayer.activePlayerList)
{
//Since I can't use puts since it's non-static or something, I use this.
person.ChatMessage("Test");
}
}
private void OnTriggerExit(Collider other)
{
foreach (var person in BasePlayer.activePlayerList)
{
//Since I can't use puts since it's non-static or something, I use this.
person.ChatMessage(other.gameObject.name);
}
}
public void InitTrigger(Vector3 size, Vector3 pos, Quaternion rot, Game game)
{

this.game = game;

transform.position = pos;
transform.rotation = rot;

if (collider != null)
DestroyImmediate(collider);

if (rigidbody != null)
DestroyImmediate(rigidbody);

rigidbody = gameObject.AddComponent();
rigidbody.useGravity = false;
rigidbody.isKinematic = true;
rigidbody.detectCollisions = true;
rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;

BoxCollider boxCollider = gameObject.GetComponent();

if (boxCollider == null)
{
boxCollider = gameObject.AddComponent();
boxCollider.isTrigger = true;
}
boxCollider.size = size;
bounds = boxCollider.bounds;
collider = boxCollider;
}
}​

 

And here's the method I'm using to create those triggers, since I can't use a constructor apparently.

static void CreateTrigger(Vector3 size, Vector3 pos, Quaternion rot, Game game)
{
Trigger trigger = new GameObject().AddComponent();
trigger.InitTrigger(size, pos, rot, game);
}​


I really have no idea why it isn't triggering. I thought maybe it was because he was attaching some sort of additional collider to players because their colliders didn't trigger these triggers, but not only is that huge stretch that doesn't really make sense to me, I can't find anything referencing that either. I'm pretty much totally at a loss, so any information would be helpful.
Hello. Got same problem some time ago. There is some layer, kinda. See what it sets it to in Zone Manager. This should fix it :)
That worked, danke.

For anyone interested, you have to add this to the class:

private void Awake()
            {
                gameObject.layer = (int)Layer.Reserved1;
                gameObject.name = "Trigger";
            }​

"triggering when an npc enters them, only when an entity does."

lol, what?

Locked automatically