Hi! I wonder if there's a way to trigger event upon collision from npc, meaning the event will be triggered when the npc collides with the player (not the opposite).

There's a few example in my game that needed this:
1. Some npc running around, and when player gets close they will start chasing the player. When they hit the player some dialogue will appear.
2. Some npc walking in a fixed direction, and if the player walks into their path and blocks their way, event will trigger upon collision between npc and player like npc saying 'stop blocking my way' and stuff.

  • edited February 18
    Event interaction -> game event on the prefab that searches for the player within a cube trigger parented to the NPC?

    You can have enemies chase using hunting in Move AI which you can look up in the tutorial.
    Post edited by Wrofir on
  • edited February 19
    Thanks for the reply!

    Yes, I am using hunt Move AI, but I'm finding a way to start an event when the npc collides the player from behind. Because the event interaction controller for the player is placed in front of him, and when something collides him from the back it doesn't trigger the event. (event interaction script component is placed on the npc, not the player, as different npc has different event interaction).

    Currently, the npc is able to hunt the player, but when it collides with the player, nothing happens unless the npc is in front of the player (due to the event interaction controller being placed in front of the player).

    Is there a solution for this?
    Post edited by Salgian on
  • There is no way to determine if object A bumped into object B or the other way round - both will get the collision events.

    Collision/trigger start types don't need the interaction controller, since the IC is only used for Interact start type (i.e. you can interact with events that are within the IC). Try enabling Start By Root Object, as you might be colliding with some child object of the player :)
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • I tried, but unfortunately it doesn't work. The event will still only be triggered when object A bump into player when he's infront of the player. If IC has nothing to do with this, what might be causing this? The event doesn't trigger if the object bump into player from behind...
  • Hm, can you post your event interaction setup?
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • image

    This is the component attached to the npc. The event will start between 2 actors, which is player and event object.
  • The Trigger Enter start type requires for a collider used as trigger to be present on the same game object and a rigidbody at at least one of the objects (i.e. the event or the player). If you're using colliders (not triggers), use the Collision Enter start type.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • I tried a little debugging based on the suggestion, and it doesn't work unfortunately. This is what I found:

    1. When I use Collision Enter start type, nothing occurs no matter how I collide with the npc. Both of them have a rigidbody component and capsule collider attached to them. I suspect it is due to me having the move AI to stop before colliding the player when chasing him (for a very short distance), which causes the collider to not collide with each other. Unchecking or checking start by root object doesn't make a difference here.

    2. When I tried using Trigger Enter start type, I realized the npc will only react to the interaction controller attached in front of the player. I tried moving the controller around during in game and it was true, the npc with the event interaction attached only react to the interaction controller component.

    How do I solve this? I want the event to be triggered when the npc bump into the player, no matter from which direction.
  • I solved my problem.

    Apparently, I found out that Trigger Enter is the one I need, and it is reacting to the box collider (with trigger) attached to the interaction controller. (collision enter start type gives no reaction at all) Knowing this, I attached a box collider on the player with trigger checked and checked start by root object. It worked! The npc reacted once it enters the box collider area.

    Thanks for everyone that commented!
Sign In or Register to comment.