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 /
  • Help Room /
avatar image
0
Question by DecreeB · Nov 28, 2016 at 04:10 PM · 2dcollidertriggerdetectionstealth

OnTriggerEnter2D Not Detecting BoxCollider2D - Childed Object

I'm trying to do a prototype for a 2D stealth/platformer and I'm trying to get the super-basic mechanics set up. This is also my first time working with Unity, so I don't know a ton, but I do know a bit. What I have right now is a player that moves via script (it has a RigidBody2D and "Is Kinematic" is enabled), as well as a basic enemy (movement same as player). What I'm currently trying to do is get the enemy to notice the player at a certain distance using colliders. I have a Line of Sight Cone that is a child of the Enemy, which also has a RigidBody2D with "Is Kinematic" un-checked, as well as a Polygon Collider 2D for detection, and a script used for detecting the player if it enters the collider.

I've already tried to set the "Is Trigger"'s in a variety of ways (both on, player on only, and trigger on only), but no matter what I do, the OnTriggerEnter2D is never used when the two collide. I have no idea what I'm doing wrong, as everyone with a similar issue either didn't have Rigid Bodies, or didn't set their "Is Trigger", and I've done all of them.

I already have an "OnTriggerEnter2D" working on the player for detecting areas that they can hide, and that works perfectly fine! I even tried to set up the player's functional OnTriggerEnter2D to detect the Line of Sight Cone instead, but that one doesn't work either. Is there something weird that I'm doing wrong?

I considered that it was because the Line of Sight Cone is a child of the enemy, but the child still has a RigidBody2D, and holds the script. It also works when it collides with my hideable objects for the player, meaning the child thing shouldn't be the issue.

Here's the script I'm using:

 using UnityEngine;
 using System.Collections;
 
 public class LineOfSightController : MonoBehaviour {
 
     public bool isSeen = false;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
 
     void OnTriggerEnter2D (Collider2D cols){
 
         Debug.Log ("entered");
         if (cols.tag == "Player") {
             isSeen = true;
         }
 
     }
 
 }
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
0
Best Answer

Answer by DecreeB · Nov 29, 2016 at 07:27 PM

After doing some testing, I've discovered it's something to do with the Prime31 CharacterController2D that is somehow breaking the ability for OnTriggerEnter2D to work properly with the player. I'm considering trying to script my own entire movement system, or just fine another. I might even try making a child specifically for the player to be detected. Either way, it'll be resolved eventually now that I found the cause of the issue.

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 josh15 · Nov 28, 2016 at 06:36 PM

i thing you should make it like this

   void OnTriggerEnter2D (Collider2D cols)[
          if (cols.gameObject.CompareTag("Player")) {
              isSeen = true;
          }
Comment
Add comment · Show 1 · 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 DecreeB · Nov 28, 2016 at 09:58 PM 0
Share

Yeah, I considered trying to rephrase the if statement, but the first "Debug.Log" that denotes when a trigger enters, regardless of the if statement, doesn't fire when it makes contact with the "Player". So, I would still have the issue of it not even entering the function as a whole, and from there I can change the if statement if necessary. Thanks for the comment, though :)

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

131 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 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

OnTriggerEnter2D() function not working 1 Answer

OnTriggerEnter2D not working 2 Answers

Coin Magnet Collider Overlap 0 Answers

How to make a growing mesh 0 Answers

Jitter with Tilemap Collider's but no Jitter on standard Box Collider 1 Answer


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