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 Weev · Dec 21, 2010 at 05:27 AM · collisionphysicscollidershield

Projectile/Shield Collisions with Friendly Projectiles Passing Through

I've been having trouble getting colliders and triggers to work with shields. This is for an RTS-style game, and I want projectiles fired from player weapons to pass through shields as if the shield wasn't there, but projectiles fired from enemy weapons to impact the shield.

My projectiles have a simple box collider and a rigidbody (non-kinematic), and my shield has a mesh collider set as a trigger with no rigidbody.

From the table at the bottom of the collider pages in the manual (i.e., http://unity3d.com/support/documentation/Components/class-BoxCollider.html ), it looks like I should be receiving OnTriggerEnter events on the shield when a projectile collides with the shield, but instead, I'm getting an OnCollisionEnter event on the projectile.

I've also tried using a simple sphere collider for the shield, but I get the same result.

How should the colliders be set up so the trigger is called instead of the collider?

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 Berenger · Dec 21, 2010 at 09:51 AM

Maybe you could work this out with link text ?

Or another way, but it sounds weird : When you get an OnCollisionEnter and if this is an ally, set the isTrigger parameter to true. I'm not sure of that approch, but it can't hurt talking about it :)

Comment
Add comment · Show 4 · 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 Weev · Dec 21, 2010 at 04:48 PM 0
Share

This may have changed in Unity 3 (I'm not sure), but I know in earlier versions by the time OnCollisionEnter is called the collision has already happened, which made doing things like IgnoreCollision useless (which sounds similar to what you've suggested). I tried this once before, and if an artillery shell hit the shield, it would just stop (because it collided with the shield) and drop to the ground, even though the OnCollisionEnter code told it to ignore collisions with the shield.

avatar image Weev · Dec 21, 2010 at 04:51 PM 0
Share

The layer-based collisions are too general because I need to handle this on a per-projectile basis. I don't want a friendly projectile to hit the shield, disable shield/projectile collisions, then have an enemy projectile pass through before the friendly shell has exited. I'd also have to somehow keep up with when a friendly projectile enters and exits the shield, which would be difficult when collisions between the two are disabled.

avatar image Weev · Dec 21, 2010 at 04:52 PM 0
Share

However... I could probably set up layers for each player (i.e., Player1Projectile, Player2Projectile, ..., Player1Shield, Player2Shield, ...) and set up collisions properly between them.

I think I'm going to try that out and get back to you.

avatar image Weev · Dec 21, 2010 at 05:03 PM 0
Share

Well, it used a lot more layers than I liked (2 * the number of players), but it worked perfectly, so you win.

If anyone else has another option (I'd really like one that uses less layers), I'd still appreciate it.

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

No one has followed this question yet.

Related Questions

Do you have to have a rigidbody component for collision detection? 1 Answer

No Collision 3 Answers

AI Players Movement for Rolling Ball Game 0 Answers

Trouble with Physics.IgnoreCollision 0 Answers

Big issue with colliders 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