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 Subhi · Oct 09, 2011 at 12:35 PM · collisioncollidertrigger

Collider won't collide with a trigger

Hi , i have a shoot that's make a spherical shock , and the shock causes an amount of damage every second , it works with my character but it wouldn't work with a cannon , the cannon have a collider and a trigger , this is the colliding code of the cannon

function OnCollisionEnter(collision : Collision)

{

if(collision.gameObject.tag == "Shoot")

{

 collision.gameObject.BroadcastMessage("Hit",gameObject);

}

if(collision.gameObject.tag == "SmallShoot")

{

 collision.gameObject.BroadcastMessage("Hit",gameObject);

}

if(collision.gameObject.tag == "Hit")

{

 collision.gameObject.BroadcastMessage("Hit",gameObject);

}

}

function OnTriggerEnter(Hit : Collider)

{

if(Hit.gameObject.tag == "Trap")

{

 Hit.gameObject.BroadcastMessage("Hit",gameObject);

 Damaged = true;

}

if(Hit.gameObject.tag == "Shoot")

{

 Hit.gameObject.BroadcastMessage("Hit",gameObject);

 Damaged = true;

}

if(Hit.gameObject.tag == "SmallShoot")

{

 Hit.gameObject.BroadcastMessage("Hit",gameObject);

}

}

function OnTriggerStay(Stay : Collider)

{

if(Stay.gameObject.tag == "SmallShoot")

{

 Stay.gameObject.BroadcastMessage("Hit",gameObject,SendMessageOptions.DontRequireReceiver);

}

}

function Damage (Damage : float )

{

 if(!NoHealth)

 {

     Health.localScale.x -= Damage / (Sturdy * 0.1);

 }

 

 if(NoHealth)

 {

     Instantiate(Destroyed,transform.position,transform.rotation);

     Destroy(gameObject);

 }

}

and thanks very much

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 syclamoth · Oct 09, 2011 at 12:41 PM 0
Share

Please- code-dumps are pretty ugly when they're that badly formatted. (they're pretty ugly anyway, because nobody wants to look through an entire script to find the one line that's making an error)

3 Replies

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

Answer by Ludiares.du · Oct 09, 2011 at 02:07 PM

If you're using a trigger, use OnTriggerEnter function instead of using OnCollisionEnter

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 Subhi · Oct 09, 2011 at 02:58 PM 0
Share

iam using a sphere collider as a normal collider and a box collider as a trigger

avatar image Ludiares.du · Oct 09, 2011 at 03:28 PM 1
Share

at least one of them needs to have a rigidbody.

avatar image
0

Answer by Subhi · Oct 09, 2011 at 04:09 PM

ok thanks everybody , i find the solution , i added a rigid body and keep the sphere collider and it works

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
avatar image
0

Answer by vic-chan · Jun 26, 2018 at 03:20 PM

thanks <3 I had the same problem.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTriggerEnter Not Working 3 Answers

Collision detection accuracy issues. 1 Answer

Collission and Trigger on Same object 0 Answers

Trigger if 3 Objects Collide at the same time 0 Answers

overlapsphere to destroy NPCs on exit 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