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 BilboStabbins · Aug 07, 2012 at 05:16 PM · raycastbullettriggerscollisiondetection

Bullet collision for space shooter - colliders, rays, etc?

Hello all,

I'm in the process of making a space shooter and need some advice on what to use to detect the collision between the player's bullets and the enemies. I know that rays are commonly used for faster moving projectiles in first person shooters, but would would be the best method for slower moving bullets - triggers, rigidbodies, etc??? I do want the collisions to be as accurate as possible too.

Any code to help get me started would also be fantastic :)

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 Paulo-Henrique025 · Aug 07, 2012 at 07:31 PM

Just add rigidbody and them use OnCollisionEnter http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html

Comment
Add comment · Show 10 · 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 BilboStabbins · Aug 08, 2012 at 10:45 AM 0
Share

Thanks Paulo,

I've used Colliders for various things and they do serve the purpose well. I was just wondering what other user's experiences of other methods is. How do rays perform for slower moving projectiles?

avatar image Paulo-Henrique025 · Aug 08, 2012 at 09:40 PM 0
Share

Why not just use the colliders? Even if you want to "predict" a collision you can use a big trigger box around the player. Raycast is a expensive technique and I'm sure you can avoid them.

avatar image wondersonic · Aug 08, 2012 at 09:44 PM 0
Share

I personnaly use colliders + rigidbodies, works pretty well!

http://www.youtube.com/watch?v=$$anonymous$$FQY$$anonymous$$YUrJsU

avatar image BilboStabbins · Aug 21, 2012 at 01:46 PM 0
Share

Thanks for suggestions.

I've tried both colliders and triggers and the detection works fine, but as the bullets are moving quickly (similar to your game, wondersonic), the collision is being detected at the middle of the object (possibly a frame or 2 later than required).

So, to use triggers/colliders for fast moving bullets, is making the colliders much larger than the object a standard practice? Is this what you did in your game, wondersonic?

Thanks

avatar image wondersonic · Aug 21, 2012 at 02:10 PM 0
Share

Exact, for my bullet, I have a larger capsule collider (trigger ON) than my bullet shape. Exactly for the same reasons you are mentioning :)

Also, in order to avoid over allocating objects, I use an ObjectPool$$anonymous$$anager! (in C#)

Show more comments
avatar image
0

Answer by Gunslinger3 · Aug 21, 2012 at 08:01 PM

You should use triggers and colliders (normal size). For the bullets rigidbody, turn collision detection to "Continuous dynamic". For the targets rigidbodies set collision detection to "Continuous". Using these settings will lead to longer physics calculations that is more precise with fast moving bullets. Take the good with the bad.

Source: http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-collisionDetectionMode.html

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

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

RayCast Problem : 2d 1 Answer

How to stop textures flickering 2 Answers

Optimization of bullet hit calculation per frame 1 Answer

Detect if GameObject is Touching an Imported Level 0 Answers

instantiate decal at raycastHit 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