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 DMCH · Oct 10, 2013 at 04:39 PM · 2dshooterpassthrough

[Top Down Shooter] Make bullets pass through some gameobjects

Hi,

Thanks for reading. My game has two factions: (player + allies) & enemies. I would like to make it so bullets which hit members of the same faction pass through them. At present, if a bullet hits a member of the same faction, it 'curls' around it. I tried hiding the bullet and its trail renderer, but the problem is more that the bullets go off course than appearance of it curling around the gameobject.

Bullets have rigidbodies, as do the members of all factions. If you need more info, please let me know!

 // If the bullet collides with an enemy
 if(Other.gameObject.tag == "Enemy")
 {
     // Get the script of the hit enemy
     EnemyScript es = (EnemyScript) Other.gameObject.GetComponent("EnemyScript");
                 
     // Damage enemy
 }
                 
 // If the object is not an enemy, hide the bullet
 else if(Other.gameObject.tag == "Ally")
 {        
     HideBullet();
 }
Comment
Add comment · Show 3
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 AlucardJay · Oct 10, 2013 at 06:02 PM 0
Share

It's extra work but make separate bullets for each faction, then use Layer-Based collision detection. Have the player bullet layer ignore the player object layer, and the same for enemy bullets : http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

avatar image AlucardJay · Oct 10, 2013 at 06:19 PM 1
Share

or also check out : http://docs.unity3d.com/Documentation/ScriptReference/Physics.IgnoreCollision.html

avatar image DMCH · Oct 10, 2013 at 09:58 PM 0
Share

Thanks for answers. Any reason why I might pick one over the other? I won't be saving the state in the scene the bullets are present in (noticed that the was some issue with this)

Tried out ignore collision. Works perfectly. Thanks. Will try out making separate bullets if I run into trouble down the line.

EDIT: Tested out both methods. Ignore collision works most, but not all of the time. $$anonymous$$ay be down to error on my behalf. Layer based seems to work all the time, and cuts down the complexity of the bullet script. Seems the better option in this case. Appreciate the help guys!

1 Reply

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

Answer by darthbator · Oct 10, 2013 at 06:06 PM

Read this

http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

You'll want to put separate factions on separate collision layers. This is the easiest way to achieve this manner of things IMO.

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

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

Related Questions

Writing weapon imprecision 1 Answer

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

2D Aiming in Physics Based Racer 0 Answers

Jittery Movement (2D) 4 Answers

How to make a simple line of sight in a 2D top down shooter. 3 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