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 kyrill91 · Feb 11, 2014 at 11:15 PM · rigidbodycolliderprefabtriggertriggers

Trigger doesn't work 100% of the time.

I am having such a hard time with this and I cant figure out why. I have two game objects: "player" and an enemy called "skeleSword". Both have rigid bodies and colliders. Player is using the FPS controller. "skelesword" has two child objects containing colliders: one on the weapon and one on the head. I scripted the weapon collider to destroy "player" on trigger enter. I scripted the Head collider to destroy "skelesword" on trigger enter. Then I made "skelesword" a prefab that spawns at random intervals. The problem I'm having is this: the body collider doesnt always detect a collision and the player falls through it.

Code:

Head Collider:

private GameObject skeleSword;

 void Start () {
     skeleSword = GameObject.FindWithTag("skeleSword");
 }
 
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Player") {
         Destroy (skeleSword);
         Debug.Log ("enter");
     }
 }

Weapon Collider:

 private GameObject hank;

 void Start () {

     hank = GameObject.FindWithTag("Player");
 }

 void OnTriggerEnter(Collider other){

     if (other.gameObject.tag == "Player" ) {
         Destroy (hank);
         Debug.Log ("enter");
     } 
 }

Here are some images from the project:

Weapon Collider is the exact same as the Head collider, but with the weapon collider script.

Comment
Add comment · Show 2
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 AdamScura · Feb 11, 2014 at 11:28 PM 0
Share

What do you mean by this?

the body collider doesnt always detect a collision and the player falls through it.

Is the player jumping on top of the enemy?

avatar image kyrill91 · Feb 11, 2014 at 11:49 PM 0
Share

yes, the player is jumping up, and falling down through the trigger.

I've noticed that it is more likely to happen if the same prefab is spawned again quickly after the previous one.

1 Reply

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

Answer by kyrill91 · Feb 12, 2014 at 12:22 AM

I figured it out! Figures... I always figure something out shortly after I resort to unity answers. So the code destroyed the prefab with the "skeleSword" tag. SO, if there was more than one of that particular prefab spawned, then they both had that tag. I changed

Destroy (skeleSword);

to

Destroy (this.gameObject);

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.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Is it possible to combine child trigger of a object to only trigger OnTriggerEnter once? 1 Answer

Simple Triggers problem. 1 Answer

OnTriggerEnter problems 3 Answers

Objects placed manually collide, but don't if instantiated? 1 Answer

How do i get OnTriggerStay2D to work? 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