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 Jab2565 · Sep 29, 2013 at 09:18 AM · rigidbodyontriggerenter

Trigger Event not Working Properly

I'm having a problem with getting a trigger event to work. I'm trying to get it so that when an enemy object collides with an object with the tag "Player" that it destroys the object. Except the event is only being triggered when the player object is falling down while it is in the air.

I made sure that the player object is a non kinematic rigidbody and the enemy object is set up as a trigger but I don't know if there is a problem with the objects or with the code itself.

Here is the code I'm using for enemy behavior:

 function OnTriggerEnter( other : Collider)
 
 {
     
     if (other.tag == "Player")
     {
     Destroy(other.gameObject);
     
     }
 
 }
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

1 Reply

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

Answer by TimXT · Sep 29, 2013 at 11:01 AM

Posting your code would help see if there's something not right.

Other than that another problem might be that the player is already inside the trigger in which case it won't work.

Trigger events fire only when a target enters the trigger, and won't work if its already inside it. Maybe that's why when your player is falling down into the trigger for the first time it's working.

Comment
Add comment · Show 4 · 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 Jab2565 · Sep 29, 2013 at 05:25 PM 0
Share

I edited my post with the code I'm using. The player object remains stationary while the enemies are instantiated and moved on screen towards it.

avatar image TimXT · Sep 29, 2013 at 07:02 PM 0
Share

Hmmm, your code seems to be perfectly fine so it's definitely something else. How are you moving your enemies btw? Remember that triggers don't work if you move an object directly using the transform.position component. If you are doing that, then you must add a rigid body component to the moving object (i.e. your enemies).

avatar image Jab2565 · Sep 30, 2013 at 03:13 AM 0
Share

That was it. I had the rigidbody on the player but not on the enemy. Added that on and it's now working, thanks.

avatar image aldonaletto · Sep 30, 2013 at 03:24 AM 0
Share

$$anonymous$$oving triggers must have a rigidbody, usually set to kinematic.

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

17 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

Related Questions

In need of help with OnTriggerEnter 0 Answers

OnTriggerEnter/Exit called unexpectedly 2 Answers

OnTriggerEnter is not working! I have tried absolutely everything I can think of. 1 Answer

OnTriggerEnter, OnTriggerExit Work Only Once 2 Answers

How do I stop a timer with OnTriggerEnter()? 0 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