Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 ghostravenstorm · Oct 26, 2016 at 11:41 PM · colliderstriggerschildren

Trigger on Child making calls to OnTrigger in Parent

I have a guard that patrols from point A and B. These points are objects with colliders that when the guard collides with it then moves in the other direction. That only if the collider on the guard itself collides with these points. I also have a child object on the guard acting as a player detector in a region in front of the guard. The player detector is making calls on the parent object to move in the other direction. Is there any way to filter which box is making calls to which object has OnTrigger?

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

2 Replies

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

Answer by OutOfRam · Oct 27, 2016 at 02:01 AM

Hello There,

The question was worded a little strangely and is a bit hard to understand, but if I do understand you correctly then what you want is to put the different trigger objects on separate layers. make a new layer and apply it to the player detector object (in much the same way you would apply a tag), then under Edit > Project Settings > Physics you will find the collision matrix (it looks like a bunch of check mark boxes. then make sure that your player detectors layer can only collider with the player or what ever it needs to collide with.

I hope this helps!

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 ghostravenstorm · Oct 27, 2016 at 06:56 PM 0
Share

This is true for real collisions that are not triggers, right? I also have solid object that interact with the floor via gravity, but given the 2D nature of my layout I want the player and other entities to pass through these objects as if they were in the foreground or background.

avatar image LucianoMacaDonati ghostravenstorm · Oct 27, 2016 at 07:17 PM 1
Share

Yes, it's true for both colliders and triggers.

avatar image
1

Answer by LucianoMacaDonati · Oct 27, 2016 at 02:07 AM

Hey man, I'm not completely sure I understand what you're trying to do but here's a couple of ideas to help you out:

  • Instead of patrolling with colliders (which is very expensive for such a simple task) you could place empty game objects with labels (so that you see them). Once you've placed your empty objects, you could run a code like this one to patrol:

    .

       // With this, you could add more than just 2 waypoints. 
         // You could even add them dynamically !
         public List<GameObject> waypoints;
         public float speed = 1;
         int currentWaypoint = 0;
     
         void Update()
         {
             if (waypoints.Count > 1) // We only want to patrol between at least 2 points
             {
                 Vector3 destination = waypoints[currentWaypoint].transform.position;
     
                 // Get my "to" vector's magnitude 
                 // You can make this 0.1f or something bigger so that 
                 // the guard doesn't have to step "exactly" on each point
                 if ((destination - transform.position).magnitude < Mathf.Epsilon)
                     // Make sure we wrap back around to start over
                     currentWaypoint = (currentWaypoint + 1) % waypoints.Count;
                 else
                     // Your movement code here, ie:
                     transform.position = Vector3.Lerp(transform.position, destination, Time.deltaTime * speed);
             }
         }
    
    
  • Another thing that might answer your question is the ability to define physics layers. You could put the guard's layers and player's on specific layers so that only the ones you choose collider with other colliders. Read this for more info.

Let me know how it goes, cheers.

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 ghostravenstorm · Oct 27, 2016 at 03:09 AM 0
Share

You gave me the same solution I'm already using. The title is the problem, not a question. I have two gameobjects with colliders that the guard moves towards then switches direction once it enters one. The problem is the collider in front of the guard being triggered on the waypoint and not the guard's main collider how I want.

Expected behaviour: Guard should switch to the next waypoint once his center collider enters the waypoint's collider.

Observed behaviour: Guard is prematurely switching to next waypoint because the child collider is triggering the script in the parent object.

avatar image LucianoMacaDonati ghostravenstorm · Oct 27, 2016 at 04:02 AM 0
Share

I see, well, first of all a thank you wouldn't hurt, right ? Second, your initial description isn't super easy to understand so let's work together. The first problem I see with your current set up is that both colliders would trigger if they're on the same layer. Try putting the child object on a new, different layer, and make sure you uncheck the box so that it does not collide with objects on the parent's layer.

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Trigger in child object calls OnTriggerEnter in parent object 3 Answers

A child component is triggering its parent collider. 1 Answer

Why my "Is Trigger" box colliders are physically colliding with other colliders? 1 Answer

Does OnTriggerStay ignore layers? 1 Answer

Problem with multiple colliders in a trigger 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges