• 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 Slapworth · Apr 12, 2016 at 04:41 PM · rigidbody2dphysics2dcollision2d

Help with Collision2D.relativeVelocity?

Hi -

I'm working on a 2D game and just added some moving obstacles (i.e. crushers), which is forcing a revamp of my collision logic to factor in relativevelocity. Can you help me understand the expected behavior?

Additional context:

  • Until now, the game featured a moving player navigating a maze of stationary obstacles, so I was able to use Rigidbody2D.velocity (and specifically its magnitude) to calculate collision damage.

  • But now, since obstacles can move and hit the player, I need to factor in their movement, which leads me to want to use Collision2D.relativeVelocity as my main factor.

  • (I've also added separate factors in related to mass, and to the dot-product of the collision relativevelocity vector vs. player velocity vector, but those factors seem to work as intended in isolation and therefore aren't part of my question.)

So here's my question: When the player hits a stationary obstacle, am I right that the player's Rigidbody2D.velocity.magnitude should be the same as the collision's Collision2D.relativeVelocity.magnitude?

That's what I'd expect, but the two aren't identical, and in a way that seems inconsistent and unclear. What factors would cause them to be different?

(FWIW, I've updated to 5.3.4p2, as I heard that was supposed to include fixes to Collision2D.relativeVelocity calculations.)

Thanks for whatever help you can provide!

Slapworth

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by karmington2 · Aug 10, 2018 at 09:41 AM

Inside the collisionEnter2d method:

rb2d.velocity is the velocity that the object has AFTER colliding. relativeVelocity is the difference between the two objects velocities BEFORE colliding.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Collision2D.relativeVelocity should be 0? 1 Answer

More realistic physics on child collisions 2D 0 Answers

Workarounds for Higher Control When Using Physics2D? 0 Answers

My player is unexplainably destroyed when collides with a collider 0 Answers

Sprites collision not working on high speeds 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges