• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

OnTriggerEnter problems 3 Answers

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

Simple Triggers problem. 1 Answer

How can I access a collider's parent's rigidbody? 1 Answer

Does OnTriggerStay ignore layers? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges