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 FlintCLeaver · Sep 24, 2012 at 11:33 AM · collisiondistancebulletdetectionsidescroller

Need advice on non-realistic bullets collision vs distance

Hello!

I need some advice on whether or not doing a distance check between a bullet and an enemy is better performance wise than OnCollisionEnter().

Right now I have my bullets only collide with enemy and wall/platformer layers and they are "destroyed" (or deactivated since I'm pooling) with OnCollisionEnter. Same goes with the enemies receiving the damage code - tied to OnCollisionEnter();

These bullets don't move at super realistic speeds- it's a stylized side scroller so think of contra or megaman speed of bullets.

Alright so would

 Update(){
 
   if(distanceFromEnemy < 0.5){
     
 //destroy and damage
 
    }


 
 }

or

 OnCollisionEnter(collision : Collision){
 //layer check
 //destroy and damage
 
 }

be more efficient?

I would like to keep the distFromEnemy in an Update() to make sure there's enough accuracy of the detection. Also if it IS distFromEnemy how would I go about defining distFromEnemy if I have a bunch of enemies on screen? Some sort of array I suppose but how should I check?

Comment
Add comment · Show 8
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 whydoidoit · Sep 24, 2012 at 02:03 PM 0
Share

The speed difference between a distance check and a collider would favour the distance check and the level of improvement of performance would depend on the types of colliders used. That said physics is pretty fast and unless your enemies are spherical a distance check might yield unrealistic looking hits + if you want the bullets to hit other obstacles it would quickly become unmanageable (and very probably slower).

avatar image FlintCLeaver · Sep 24, 2012 at 11:32 PM 0
Share

Thanks guys! The bullets move slow enough to view onscreen. I will eventually test out both methods in empty scenes. What I wanted to do was use OnCollisionEnter() to check collisions with walls and such. (which is what i do now) but perhaps improve the performance of the enemy/bullet collisions by using distance checks ins$$anonymous$$d on OnCollisionEnter(). $$anonymous$$y enemies ARE using a sphere collider as I need them to move up ramps with velocity as there main method of moving - is there a better way?

Here is a video to my game that i'm trying to improve.

http://www.youtube.com/watch?v=1obFkye$$anonymous$$wE8

avatar image FlintCLeaver · Sep 25, 2012 at 11:58 AM 0
Share

Hey thanks :) it's definitely something I've put a lot of work in these past few months. And I'm releasing a huge update Today version 1.5. -

Yes, it's what I'm doing to ignore collisions between unwanted objects. I use it for some raycast operations and generally to avoid registering unnecessary trigger collisions.

avatar image Fattie · Sep 25, 2012 at 12:09 PM 0
Share

gotchya. my only other comment would be it's odd you're having the slightest performance problems, it looks totally easy-going to me - indeed are you sure you HAVE a performace problem? that is a trivial amount of colliders etc. should be AO$$anonymous$$ I would have thought !

avatar image whydoidoit · Sep 25, 2012 at 12:35 PM 0
Share

Agreed there are very few bullets on screen in the demo!

Show more comments

1 Reply

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

Answer by Fattie · Sep 24, 2012 at 02:12 PM

Joseph just FWIW

you mention "keeping track of enemies some sort of array"

Here is a novel-length answer

http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html

funnily enough it actually includes the very typical "closest of pool" idea as an example

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 FlintCLeaver · Sep 24, 2012 at 11:32 PM 0
Share

wow this is great! thanks for helping me out so much lately!

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

11 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

Related Questions

Collision Detection between certain objects 2 Answers

Optimization of bullet hit calculation per frame 1 Answer

collision wont work 1 Answer

Best practice for OnTriggerEnter detection 1 Answer

Create Bullethole with onCollisionEnter 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