Search Unity

the normal vector of a collision changes as the impact speed changes

Discussion in 'Physics' started by estratega2016, Sep 12, 2019.

  1. estratega2016

    estratega2016

    Joined:
    Dec 28, 2016
    Posts:
    10
    Hello, I am making collisions between spheres, with a Sphere collider and a rigidbody each.
    The problem is that when I apply a force to one sphere (sphere 1) and it collides with the other sphere, the normal vector of the collision varies according to the speed applied to the sphere (sphere 1).
    This problem is greater when the spheres do not collide just in front, but collide rubbing.

    Does anyone know how to solve this and get the correct normal vector of the collision?

    Thanks in advance
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    The collision normal isn't a surface normal, it's the normal along which the impulse is applied to both objects. If the colliders overlap then the impulse is typically applied along a vector that gives the quickest separation.

    If you're using discrete col-det then they'll overlap when they collide, perhaps only a little but more when they move faster so depending on how they overlap the normal will change.

    If you're using continuous then typicaly the normal should be the normal at the point of collision which is closer to the surface normal.
     
    xorpheous likes this.
  3. estratega2016

    estratega2016

    Joined:
    Dec 28, 2016
    Posts:
    10
    Thanks for answering.
    I am using continuous Dynamic.

    But I have tried all the options I think, modifying the PhysicsManager options such as the rigidbody options and also the physical materials and I still have the same problem: if the impulse speed changes, the normal collision vector is no longer the same.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    I'm not on the 3D physics team but maybe you can post more info, even a test project or something and I'll see if I can help. I know this would work in 2D but maybe this is something in 3D (physx) I'm not aware of.
     
  5. estratega2016

    estratega2016

    Joined:
    Dec 28, 2016
    Posts:
    10
    ok nothing happens, thanks anyway.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Nothing happens? Sorry, I don't follow.
     
  7. estratega2016

    estratega2016

    Joined:
    Dec 28, 2016
    Posts:
    10
    Is that my project is in 3d, and as you said "I'm not aware of." That's why I told you that.
    Thank you anyway.
    I'm sorry if I express myself badly, I don't speak English well and I use the translator,: D
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,920
    Not a problem. Can you share a project so I can take a look at it?

    You can upload here if you like.
     
  9. estratega2016

    estratega2016

    Joined:
    Dec 28, 2016
    Posts:
    10
    I don't have much to show you, the project I'm on is more a test than a project itself.
    I really just needed to know if it was possible to obtain a correct normal vector, and if it is not possible there will be no project.
    I want to say that in order to start the project I needed to know if the physical engine of unity could do that, and how I see that it can't (or don't know how to do it) because I can't even start doing it.
     
  10. xorpheous

    xorpheous

    Joined:
    Mar 28, 2018
    Posts:
    17
    I'm not sure how specifically within the physics engine to have it return the true surface normal, but for sphere's it is an easy thing to compute. The line connecting the centers of the two spheres will be co-linear with the contact normal (barring a bit of variance due to penetration/overlap).

    Let's call the position of the moving sphere posA and the position of the sphere with which it collides posB. The vector that points from sphere B to sphere A, relPos = posA - posB. You can then use the Vector3 function "normalized" to give you a normal vector that points from B to A.

    Code (CSharp):
    1. collisionNormal = (posA - posB).normalized
    This won't be exactly perfect, because of the overlap, but it will be close and may give you the direction vector you're seeking and it will be good enough in most cases so long as your speeds are relatively low so that your overlap is relatively small.
     
  11. estratega2016

    estratega2016

    Joined:
    Dec 28, 2016
    Posts:
    10
    Yes, the problem is that in my project I need the collisions to be good at different speed values.
    That is, I need the normal vector to be identical even if the speed changes.
    I've done a little test so you can see it better.
    Just give the play in unity and you can see by console the normal that is obtained from a collision and the other, both in the same situation but with different speeds, you can see how the normal varies.

    https://oc.unity3d.com/index.php/s/Rn0HjdiLtYoXZCs