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 Griffo · Jun 03, 2012 at 08:11 AM · ontriggeroncollision

OnTrigger, OnCollison

Hi,

Im having trouble with OnTrigger and OnCollision, I've built a animated mouse and paired a weapon (a pole) by script to its left hand, the weapon has a capsule collider on it and I've set its trigger to on, now in the scene I have a box (cheese box) with a box collider so when the mouse swings the weapon and hits the box the script attached to it (and below) should be registering the hits but its not working, I've also tried OnCollision with the weapon trigger off again with no luck, is it something to do with the weapon being paired by script to the left hand?

Any help would be greatly appreciated.

 var explosionPrefab : Transform;
 var sparklePrefab : Transform;
 var WoodSound : AudioClip;
 var MetalSound : AudioClip;
 var BrickSound : AudioClip;
 var audioSources;
 
 private var CheeseBoxHitCount = 0;
 
 function OnTriggerEnter (other : Collider)
 {
     audioSources = new AudioClip[5];
      
     if(other.gameObject.tag == "CheeseBox")
     {
         audio.PlayOneShot(WoodSound);
         CheeseBoxHitCount = CheeseBoxHitCount + 1;
     }
     else if(other.gameObject.tag == "MetalBox")
     {
         audio.PlayOneShot(MetalSound);
     }
     else if(other.gameObject.tag == "Wall")
     {
         audio.PlayOneShot(BrickSound);
     }
         
     var explodePosition : Vector3 = transform.TransformPoint(Vector3.zero);
         Instantiate(explosionPrefab, explodePosition, Quaternion.identity);
 
     if(CheeseBoxHitCount > 2 && other.gameObject.tag == "CheeseBox")
     {
         Destroy (other.gameObject);
         var sparklePosition01 : Vector3 = other.gameObject.transform.position;
         Instantiate(sparklePrefab, sparklePosition01, Quaternion.identity);
         CheeseBoxHitCount = 0;
     }
 }
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
2
Best Answer

Answer by David C · Jun 03, 2012 at 08:26 AM

I may be wrong here but when using OnTrigger one of the two colliders needs to have a rigidbody attached as well as at least on of the colliders need to have isTrigger checked.

Try this and if it doesn't work come back and I will try and help!

Comment
Add comment · Show 2 · 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 fafase · Jun 03, 2012 at 09:01 AM 1
Share

Indeed,you need to add a rigidbody and tick IsTrigger on one of them.

OnTrigger is a way to check collision without using the physics engine. When using OnCollision, the engine makes the two rigidbodies bounce against each other depending on many variables. With OnTrigger you simply can check if they are colliding but nothing physical happens.

I just clarify since you say you are not sure.

avatar image Griffo · Jun 03, 2012 at 09:51 AM 0
Share

Ok, I've tried all that with no luck so I've gone right back to basics, I'm using a modified version of the 3RD person controller in the standard assets folder, so I've created a new project and 1 scene in that scene I have the 3RD person controller, a plane (floor) and a box with ridged body, I've attaché the script to the 3RD person controller with a debug line to tell me when it collides and what with (Debug.Log("Collided with " + gameObject.name);)

I've tried this with OnTrigger to with trigger ticked, I've also tried it with the script on the box and I can not get it to detect.

Is it something to do with the way the 3RD person controller is written? I have noticed it already has a collider built in, I've tried adding an other with the same results ..

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTrigger & OnCollision not working? 2 Answers

Performance difference between OnCollision and OnTrigger messages? 2 Answers

How to change the position of the camera when colliding with a GameObject? 1 Answer

How to get the collided plane of a mesh, not just the object,How to get the collided plane of a mesh 1 Answer

Item pickup, OnTrigger vs Raycast? Which is best? 2 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