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 KaRa777 · Feb 21, 2014 at 02:12 PM · physicsrigidbodycollidercompound collider

Problems with OnCollisionEnter, rigidbodys and compound colliders

Hi there, I have a problem with the OnCollisionEnter method. The situation is this. I have a moving truck with a rigidbody and a container with 6 box colliders attached as a child. Like you can see in the screen my truck is doing random moves on this street like braking, changing lanes, rumbling over the sidewalk and so on. Everything is done with physics so the objects inside (also rigidbodys) fly around. This works fine so far.

alt text

My problem is that I want to calculate the damage which the objects have taken during the ride. So far I use coll.relativeVelocity.magnitude for that. But this is used best in OnCollisionEnter in a script attached to the objects. This event is immediately fired by the floor so the collisions with the walls are ignored, because it is a compound collider (Except it leaves the floor, but that happens rarely). I also tried it in OnCollisionStay but then the friction with the colliders cause the most damage. Sadly I can’t make use of the collision.contacts because they haven’t something like relativeVelocity.

If I attach rigidbodys to the box colliders the truck behaves totally different and can’t even move forward.

I think my best approach was to create a CollisionListener script and attach it to the 6 box colliders. But somehow the OnCollisionEnter isn’t even fired.

 public class CollisionListener : MonoBehaviour 
 {
     void OnCollisionEnter(Collision coll)
     {
         Debug.Log("Here");
         if (coll.gameObject.tag != "Finish")
         {
             if (coll.relativeVelocity.magnitude > 0.9f)
             {
                 coll.gameObject.GetComponent<Damage>().GiveRelativeVelocity(coll.relativeVelocity.magnitude);
 
             }
         }
     }

}

So is there any solution how I can handle more collisions in the OnCollisionEnter, access the single box colliders, calculate the impact velocity in a different way or something I have tried so far in a correct way :-).

screen.png (236.5 kB)
Comment
Add comment · Show 5
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 · Feb 21, 2014 at 02:15 PM 0
Share

The truck should behave the same if the only things with rigidbodies are the items inside the truck.

avatar image unimechanic ♦♦ · Feb 21, 2014 at 03:36 PM 0
Share

This question could have different correct answers, and is mostly intended for discussion of best practices, you could post it in the forums ins$$anonymous$$d in order to receive more ideas.

avatar image KaRa777 · Feb 21, 2014 at 08:10 PM 0
Share

Im using rigidbody.AddForce and rigidbody.$$anonymous$$ove to $$anonymous$$Ove the Truck, and I got pretty good results with it, so I would like to stick to this concept. How should I manipulate the truck without a rigidbody?

avatar image whydoidoit · Feb 22, 2014 at 10:52 AM 0
Share

Truck has a rigidbody as do the items inside it - but not each part of the truck.

avatar image KaRa777 · Feb 23, 2014 at 01:54 AM 0
Share

Yes thats what I'm doing. The Parent "Truck" got a rigidbody. In it a child "rear" with a renderer and materials. Rear got a child "Colliders" what is an empty game object. And "Colliders" got the six box colliders as children. Is this wrong?

2 Replies

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

Answer by KaRa777 · Feb 26, 2014 at 11:54 AM

I got a solution. Took me a while beacause I'm relative new to Unity. For anybody who looks it up: You have to detach the colliders and connect them with the old parent via a fixed joint. Then the walls will have an own rigidbody but will stick with the position of the truck. Now they wont act as a compound collider and you can work with the OnCollisionEnter() of each side.

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

Answer by MrYOLO · Feb 27, 2014 at 10:02 AM

I think Layer in unity will help you in this situation. You can set the object you wanna calculate the damage to the same layer, so the OnCollisionEnter will only be called when the things in the same layer colliding with each other. Through this, you can ignore the influence from other unecessary colliders(like floor you dont want), then in OnCollisionEnter function, you can get the damage degree you want, good luck!

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

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

Related Questions

Camera gets flung off of the map when the player collides with certain objects. 0 Answers

Ignore sub-colliders for center of mass in Rigidbody2d? 1 Answer

Tossing an object with the correct force at any distance from another so that it collides with the other 1 Answer

Physics Possibilities?: Angles, Penetration, Exceptions 4 Answers

ball's collider sometimes catches an edge and bounces. when ball rolls over two aligned platforms 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