Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ithemes · Jul 23, 2014 at 10:53 PM · triggerontriggerenter

Problem with OnTriggerEnter()

Hey guys! I'm making a Doom-style FPS (meaning the Y-axis is locked). Anyways I want the raycasts from shooting to aim up or down based on the enemy the player is looking at. The best workaround i could figure out for this is to attach a trigger box collider to an empty object on the camera that determines the relative Y angle to the enemy when AI enters the box. I'm having trouble getting the OnTriggerEnter() to call (whereas OnTriggerExit() works just fine). Here's a visual example: alt text

  • There is a collider and rigidbody attached to ALL AI

  • The trigger box attached to the camera is large enough to completely fit the AI

  • The script is attached to the same game object as the trigger

  • They're all on the same layer (which is set to respect physics on collision with itself)

Here's some of the script:

 private var colliderCount = 0;
 
 function OnTriggerEnter(hit : Collider){
     Debug.Log(colliderCount + "registered");
     if (hit.transform.tag == "AI") {
     colliderCount++;
     Debug.Log(colliderCount);
     }
 }
 
 function OnTriggerExit(hit : Collider){
     if (hit.transform.tag == "AI") {
     colliderCount--;
     Debug.Log(colliderCount + "registered");
     }
 }


I'd be really happy if someone could help me figure it out (or provide a better workaround than the one I'm using), and I'd be happy to provide pictures of my kitten as a 'thank you'!

2014-07-23_1542.png (53.8 kB)
Comment
Add comment · Show 1
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 cdrandin · Jul 24, 2014 at 12:00 AM 0
Share

Could you elaborate more on your problem. It is not entirely focused and are introducing multiple issues.

Is it simply an object entire your collider is not trigger the event or a problem with shooting a raycast at an enemy location?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AmarokStudios · Jul 23, 2014 at 11:59 PM

On the collider for the trigger, do you have "Is trigger" ticked?

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 ithemes · Jul 24, 2014 at 12:00 AM 0
Share

Yes I do :(

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Why is my script not working like it should 3 Answers

Can't figure out how to use multiple triggers in single scene 1 Answer

how to go through platform like bananakong? 1 Answer

Damage rate HELP 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