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
1
Question by supermodular · Apr 28, 2012 at 08:43 PM · collisioncolliderbestpractices

Collision Questions

Hi folks. I've just gotten collision detection working for the trains in my game. When a train realizes it has bumped into another train, it turns around. I'm not using any physics. I've got three questions for you all:

1) In my testing, when two trains collide, they both turn around, as they should. But I'm worried I've just gotten lucky. Since each train detects the crash independently, is it possible that the first train detects the collision, turns and moves, and thus when the second train checks for a collision, it isn't found, since the first train has already moved away? Or is the collision reported to both parties as soon as it registers?

2) I'd like colliding trains to spawn a small crash/flying-debris animation. I don't want both trains to spawn a crash, but the obvious solution would do just that. Is there a natural way to spawn just one? I realize I could index the trains and have the smaller-indexed train handle the crash animations, but I was hoping there might be a cleaner approach.

3) My trains are basically empty game objects containing a health bar, a train script, and the model of the train. Currently the model has the rigidbody and collider on in, and a script whose sole purpose is to tell the main script that a collision has happened. Is this a reasonable way to handle things? It seems a little clunky, but I'm new to all this stuff.

Thanks very much in advance!

Comment
Add comment · Show 2
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 Lo0NuhtiK · Apr 28, 2012 at 09:26 PM 0
Share

Note : a game object with a health bar, a script, a model(mesh), a rigidbody, a collider, and another script is not 'basically an empty game object'.

avatar image supermodular · Apr 28, 2012 at 10:25 PM 0
Share

Sorry, I just meant that not much is at the top of the hierarchy: the mesh, rigidbody, collider and other script are all components of a child.

1 Reply

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

Answer by aldonaletto · Apr 29, 2012 at 12:38 AM

1- Collision events are sent to both colliders, thus you will not miss the collision.
2- Since both trains receive the collision event, you must use some trick to avoid a double explosion - something like the index you've mentioned. You could give different names to the trains, and compare them in the collision event:

function OnCollisionEnter(col: Collision){
  if (name < col.gameObject.name){ // the "lower" name handles the explosion
    var pos = col.contacts[0].point;
    Instantiate(explosion, pos, Quaternion.identity);
  }
}
3- I think you hierarchy is ok - frequently we must child the model to an empty object to adjust axes and/or the pivot; the empty object becomes then the actual object, to which we attach the main components: scripts, collider, rigidbody etc.
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 supermodular · Apr 29, 2012 at 06:17 PM 0
Share

Thanks, that's what I was looking for!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Destroying object when player walks over it 1 Answer

Ignore collision at high velocity. 1 Answer

Trouble with Physics.IgnoreCollision 0 Answers

Unwanted jittery behavior 2 Answers

Colliders in a wall jut out 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