• 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 Paul Ripley · Sep 18, 2013 at 01:47 PM · collisionphysicsvelocityrelative

Why is the relativeVelocity of a Collision always zero in OnCollisionEnter and OnCollisionStay?

I am colliding a GameObject (with a rididBody and a capsuleCollider on it) with a static mesh collider (the game world).

The relativeVelocity member of the Collision parameter in OnCollisionEnter and OnCollisionStay always has a magnitude of zero.

Surely it's impossible for objects to collide if they have no relative velocity?

Comment
Add comment · Show 1
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 Paul Ripley · Sep 18, 2013 at 01:45 PM 0
Share

I've just partly answered my own question - it looks like a bug.

The RigidBody has all the constraints set - it's position and rotation are both frozen in X, Y, and Z. It's position is deter$$anonymous$$ed by the hierarchy of GameObjects it is parented by.

If I remove the constraints, I get a valid relativeVelocity.

However, my original point still stands. Just because I am constraining the object doesn't mean that the collision between 2 objects doesn't have a relative velocity.

How do I request a fix for this problem in Unity?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Sep 18, 2013 at 04:03 PM

The physics system does a great job of bouncing around balls and cubes, but, IMHO, anything more complex is known to take a lot of care and feeding.

Take a look at the "compound collider" system. One trick is to have OnCollision only on the parent -- all child subcolliders will then count as the parent collider. Can also manually test-for and find your own parent, or test you are merely a child subcollider (a single collision will fire you and your parent's OnCollsion.)

Rigidbodies are meant to be frozen by setting isKinematic true. I wouldn't be surprised if there are some cases where a fully contrained RB acts differently from a kinematic one. The constraint system, again IMHO, is known to have combinations which just act odd.

Comment
Add comment · Show 3 · 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 Paul Ripley · Sep 18, 2013 at 04:27 PM 0
Share

Hi Owen, thanks for the reply.

Unfortunately, I can't freeze the rigid body using Is$$anonymous$$inematic, as I'm trying to detect collisions with static mesh geometry, and it looks like kinematic bodies won't interact with that!

It appears that the velocity on the rigid body in my case is always a zero vector, so I guess that is why the collision's relative velocity is also zero.

Incidentally, I tried using compound colliders as you described, but that seems to unearth another problem - I need to exactly track OnCollisionEnter and OnCollisionLeave events, but sometimes with multiple colliders parented by a single rigid body, the collision starts on one collider (and you get the Enter event), and then the collision transitions onto a second collider and when it leaves, you get no Leave event :(

avatar image Glurth · Jan 16, 2015 at 05:03 PM 0
Share

I wonder if something like this would work for you. I have not tested this myself, just an idea:

     static Vector3 getTrueVelocity(Rigidbody child_rigid_body)
     {
         Rigidbody parent_rigid_body=child_rigid_body;
         while(true)
         {
             parent_rigid_body=child_rigid_body.GetComponentInParent<Rigidbody>();
             if(parent_rigid_body==null)
                 return Vector3.zero; //failed
             if(parent_rigid_body.velocity.sqr$$anonymous$$agnitude!=0)
                 return parent_rigid_body.velocity;
             child_rigid_body=parent_rigid_body;
         }
     }    
avatar image Owen-Reynolds · Jan 16, 2015 at 05:15 PM 0
Share

Glurth: try to check dates if you can (this is 4 months old.)

Of course, if you've had the problem, and Solved it, then feel free to add the solution the mostly relevant thread, no matter how old.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Velocity Relative to Rotation 1 Answer

Ignore collision at high velocity. 1 Answer

Character accelerates while running towards walls. "Sonic effect" 1 Answer

I want collision boxes to be precise without overlapping each other 1 Answer

How to transfer bat's transnational and angular velocity to ball to simulate realistic ball movement. 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