Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TheIBPoliceman · Aug 22, 2011 at 06:25 PM · instantiatecollidersdisable

Disabling collsions between MeshColliders and bullets

I'm looking to disable collision between an instantiated bullet and the object firing it. I looked at a couple previous answers regarding collider disabling, but didn't really manage to make this work.

So I have an object (asteroid with a turret on one side) of the form + GameObject with attached behaviours --Turret 'origin' gameobject (where the weapons fire comes from) --Mesh with a MeshCollider

So the collision between this meshcollider and the shell should be disabled. Here's what I tried:

 // Fires a prefab given a position and a direction
 function FireWeapon(gunPos:Vector3,gunAim:Quaternion) {
     var shell:Rigidbody;
     shell = Instantiate (weaponPrefab, gunPos, gunAim);
     // need to disable collision between shell and self
     var colSelf= GetComponentsInChildren(MeshCollider);
     for (var  col : MeshCollider in colSelf) {
         Physics.IgnoreCollision(shell.collider, col,true);
         Physics.IgnoreCollision(col,shell.collider, true);
     }
     
     // set the shell speed to what we need
     shell.velocity =  rb.velocity+turretBarrel.rotation*Vector3(0,0,muzzleSpeed);
 }
 

As you can see, I'm iterating through all the colliders in the children (eventually, shells might be fired through more complex objects, I want to make it robust), and disabling the colliders. However, it's not working. Debugging shows that colSelf is assigned to the correct collider, and shell.Collider correctly gives the bullet collider.

I'm kinda stumped! Thanks in advance.

-EDIT: I found some new info - my bullet has a script that kills it when OnCollisionEnter plays:

 function OnCollisionEnter(collision: Collision) {
 
 var contact = collision.contacts[0];
 var rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
 PlayHitFX(contact.point,rot);
 DoDamageToTarget(contact);
 KillProjectile();
 }

Disabling this code causes the collision to be ignored. I can't find anything in the documentation about this, but is it possible that IgnoreCollision causes the physics collision to be ignored, but still sends the collision event?

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

Answer by flaminghairball · Aug 22, 2011 at 07:38 PM

Not sure what your problem is, but you don't need to have two calls to Physics.IgnoreCollision - one will do it. Also, if you're looking for robust behavior, you'll want to change GetComponentsInChildren(MeshCollider) to GetComponentsInChildren(Collider). This will take primitive colliders into account as well.

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 TheIBPoliceman · Aug 22, 2011 at 08:45 PM 0
Share

Thanks! This will help eventually. The two calls are a result of me trying to see if I had to disable collisions in both directions.

avatar image
0

Answer by Joshua · Aug 22, 2011 at 06:55 PM

Easiest is probably to set up collision layers. Create the layers you want: bullets and ignorebullets and set them up through Edit > Project Settings > Physics.

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 TheIBPoliceman · Aug 22, 2011 at 07:14 PM 0
Share

I tried this method at first, and it does work well for one enemy and one player, but if I add more enemies, I need to start having layers for "collides with player, collides with enemy 1, collides with enemy 2", etc. Since I plan on having a couple dozen such objects, it would get really complex really fast.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Checking if object intersects? 1 Answer

Can anyone help check for colliders in this spawning script so that the spawns don't overlap each other or spawn inside of walls, objetcs etc 0 Answers

how to disable instantiating projectile for the moment when the player jumps and hits the space bar to fire? 2 Answers

Turn off all Colliders from Scene 1 Answer

A tricky problem with Particle Collisions 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