• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AceToAced · May 19, 2018 at 07:40 AM · colliderstriggersiskinematic

OnTriggerEnter and Exit triggering simultaneously constantly

I have a NavMeshAgent (Enemy) that patrols around. it has two colliders one on the parent and one on the child. One much larger that the other. the child collider is use to see if the player is in range to be chased and the parent collider is to see if it is range to attack the player. The child collider OnTriggerEnter/Exit/Stay gets triggered appropriately but the Parent Collider triggers OnTriggerEnter/Exit simultaneously and constantly when the player is in the parents collider.

When i select the IsKinematic box on the rigidbody of the parent this problem is solved and OnTriggerEnter/Exit gets triggered at the correct times. the problem is that i would like to apply forces to my enemy and IsKinematic removes that option. Any idea why turning on isKinematic solves this problem? and is there a solution to this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by NEGATIVERAGDOLL · May 19, 2018 at 12:51 PM

Instead of using triggers you might want to look into using Vectors, it is a lot easier and usually works a lot better. For example you could use something like
if (Vector3.Distance(other.position, Player.position) <= 10) other is the object and player is the player. It will check the distance between you and the enemy object, if it equals 10 or below ("<" means below) whatever you want to happen can happen. You can then do the reverse for if you're a certain distance away.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AceToAced · May 20, 2018 at 01:41 AM 0
Share

Thanks for the help, I think your approach should fix the problem.

avatar image NEGATIVERAGDOLL AceToAced · May 22, 2018 at 05:59 AM 0
Share

No problem, if you need anymore help don't hesitate to ask :)

avatar image
1

Answer by jonnydredd · May 20, 2018 at 03:26 AM

No idea about why Kinematic would cause this, but I'm pretty sure swapping the colliders would solve this, as in, put the smaller collider on the parent and the larger chase box on the child. It seems like if the parent is triggered then it triggers the child too? Perhaps another method would be to have no collision on the parent, but have two children, one for chase box one for close collision, so they are called separately, without considering each other.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Guynelk · Feb 12, 2020 at 04:00 PM

Triggerstay and triggerexit will work simultaneously if you have a rigidbody to the parent and child. I had the same problem and when I deleted the parent's rigidbody, the collisions in child whose collision I wanted to detect worked correctly. I don't know if it will work for you but I took several days or even a week to find out

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

87 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Having problems with playing a sound (C#) 2 Answers

Two colliders on GameObject with only one acting as trigger 2 Answers

Destroying objects within collision 1 Answer

Does OnTriggerStay don't detect a collision with a non-trigger collider? 1 Answer

Problems with the Trigger Collider (randomly fictional) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges