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
1
Question by Sir Mate · Mar 11, 2012 at 01:00 PM · collisioncolliderdestroy

Hit Collision with exceptions

Hello

I am trying to make a projectile, which destroys itself upon impact. The problem is ,i need it to ignore some objects ,such as the character controllers collider, and i am flummoxed why it wont work. My solution is:

 function OnCollisionEnter ( hit : Collision){
 
 if (hit.gameObject.tag !== "MainCamera" || hit.gameObject.tag !== "DontDestroyProjectiles" ) {
 
 Destroy (gameObject);
 
 }
 
 }
 

Also i have been fiddling with Physics.IgnoreCollision ,without results. Maybe it would work with that, and if someone found a way with this ,please explain it troughly, becouse im pretty dense.

Any help would be greatly appriciated. Thanks!

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

2 Replies

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

Answer by kalvinlyle · Mar 11, 2012 at 05:51 PM

Use physics layers if you want to ignore collisions between types of objects. It doesn't require coding and it will be faster as the collision will not take place and therefore no code will be run.

Comment
Add comment · Show 1 · 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 Sir Mate · Mar 11, 2012 at 06:49 PM 1
Share

Heh, thanks man ,i looked up this layer collision matrix, and it works perfecly! Thanks again.

avatar image
0

Answer by henry96 · Mar 11, 2012 at 02:13 PM

I find a bit of issue in your coding. I don't know if that's the cause of the problem. You should use "!=" instead of "!==" . Also, since this script is for projectile, I suggest you use Trigger because Collision sometimes causes slowness to the object.

Comment
Add comment · Show 5 · 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 Sir Mate · Mar 11, 2012 at 02:24 PM 0
Share

I changed it to != , didnt change a thing. Also, i need colliders ,becouse i want the projectile to influence rigidbodies;which it does, the box goes flying, only it destroys itself upon connecting with and colliders. Thanks for the reply!

avatar image fafase · Mar 11, 2012 at 03:39 PM 0
Share

If the change of !== to != did not change anything, it means your problem is somewhere else becuase it should have made a difference. Try to start with only the collison function and destroy and see how it interacts. Then start adding condition until it goe sthe right way. Also, I might be stupid but I don't really get what is happening. Is the projectile exploding or not and whether or not it explodes what is happening to it and around?

avatar image henry96 · Mar 11, 2012 at 03:41 PM 0
Share

That's strange because I think the code is fine the way it is. Go over what you have done, maybe it gives you some clues.

I also find a bit of issue with Unity 3.5 scripting. Some script works fine in 3.4.2 but kinda not working in 3.5.

avatar image fafase · Mar 11, 2012 at 03:59 PM 0
Share

!== is not fine. != is fine or == is fine.

avatar image Sir Mate · Mar 11, 2012 at 04:44 PM 0
Share

Okay, this is getting ridickolous. I have changed it to "hit.gameObject.layer" , so that it would be easier to deter$$anonymous$$e the problem, so my code is now:

function OnCollisionEnter ( hit : Collision){

if (hit.gameObject.layer == "Something" ) {

Destroy (gameObject);

}

}

But its working completely ass-backwards! In this case ,nothing destroyes the projectiles, not even the layered objects, whereas if i change it to != than EVERYTHING destroyes them ,again ,even the layered objects.

What kind of sorcery is this?

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

destroy touch the screen on gameobject in camera 0 Answers

OnTriggerEnter - destroy (this.gameobject) if it collides with anything 2 Answers

Destroy the gameObject after seconds when not hit. 0 Answers

Non - Physics collision System 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