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 Niluk93 · Jul 31, 2012 at 02:02 PM · physicsprogrammingcolliders

How can I make two colliders pass through each other?

Hello, I am making a game with a character who has four types of bullets, one of which gives a small damage but passes through the enemy. My problem here was that whenever I fired the bullet it stuck to the first enemy itself and destroyed itself after the time I set. To counter this I thought maybe I could set the gameObject.isTrigger = true whenever the collision happens, so the bullet would pass through it and when it is out of the object I set gameObject.isTrigger = false, so that it would turn on collision physics again. Now whenever I run the game and fire that bullet, it hits the first enemy and then unity simply crashes. Because of that, I haven't been able to find the error as well. Can you please suggest any other method that might be more successful, or a correction for the code I used which I have written below,

 function OnCollisionEnter(bullet : Collision){  

if(bullet.gameObject.name == "stunbullet"){
//stun bullet code
}
else if(bullet.gameObject.name == "damagebullet"){ //damage bullet code } else if(bullet.gameObject.name == "pushbackbullet"){
//push back bullet code
}
else if(bullet.gameObject.name == "piercebullet"){
ApplyDamage(1) //Code to Apply Damage on the enemy object
while(bullet.gameObject.name == "piercebullet"){
gameObject.collider.isTrigger = true;
}
gameObject.collider.isTrigger = false;
}
}

all the other types of bullets are working fine except the pierce bullet which should go through the enemies.

Help would be most appreciated

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
2
Best Answer

Answer by DESTRUKTORR · Jul 31, 2012 at 03:42 PM

use Physics.IgnoreCollision

whole thing is worked out for you, with that method. Documentation can be found here

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 Niluk93 · Jul 31, 2012 at 05:34 PM 0
Share

worked perfectly. Thanks a lot.

avatar image DESTRUKTORR · Jul 31, 2012 at 08:55 PM 0
Share

No prob :)

avatar image masabusharif · Oct 17, 2012 at 12:42 PM 1
Share

how did u manage to decrease the enemy's health if you ignore collisions between him and the bullet?

avatar image DESTRUKTORR · Mar 28, 2013 at 01:30 PM 0
Share

You don't need a call from a collision or entry of a trigger to detect if something is within the bounds of the object. Just check if the distance is short enough, or use a raycast (the former is a slight bit more complicated, admittedly, but it would be a lot less costly to perform than the latter).

And yes, I realize this was posted over a year later... XP

avatar image masabusharif · Apr 01, 2013 at 08:19 AM 1
Share

Its ok, i appreciate your response :), well the solution for what i wanted was checking for distance, and everything went perfectly, thank you

avatar image
0

Answer by Loius · Jul 31, 2012 at 04:03 PM

The only code you even have is in the pierce bullet section, and it's a while loop that can never exit. A while loop runs until its condition becomes false and that condition can never be false inside that loop.

If you want to use a while loop it either needs to yield or eventually make its condition false:

while ( true ) { x++; yield; }

while ( x < 10 ) { x++; }

Ignore collision prevents collision from happening. The best way to ignore collision between groups of objects is to put their prefabs on different physics layers and then set the project's physics settings so those layers don't collide.

Triggers are able to pass through each other without colliding but you need to use OnTriggerEnter instead of OnCollisionEnter.

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 Niluk93 · Jul 31, 2012 at 05:34 PM 0
Share

Vincenti: There was no code in the other sections was because it was working fine and I didn't want to type it all.

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Using cylinder colliders as wheels. 1 Answer

Rigidbody Sliding UP Incline 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

I'm having troubles using a Capsule Cast 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