Search Unity

Question Vehicle physics. How to get WheelHit.force in dots

Discussion in 'Physics for ECS' started by Alex33333333, Mar 8, 2021.

  1. Alex33333333

    Alex33333333

    Joined:
    Jan 3, 2017
    Posts:
    11
    Hi. I'm trying to write my own vehicle physics for my project, using dots. I watched a tutorial called "The science of off-roading: Uncharted 4's 4x4" and I'm wondering how can i implement a few things described by the speaker.



    1. At 2:40
    Speaker says that wheel collision was turned off and havok's point-constraints were used instead. How can I constrain rigid body to the point in the world (not another rigid body)?

    2. How can I get "normal force" from point-constraint, mentioned in the video? I guess "normal force" of point-constraint is the same as the force we can get from WheelHit.force and it can be used to calculate tire friction.

    3. At 4:40
    what is the "shape cast"? Is it collider cast?





     
    Last edited: Mar 8, 2021
  2. Sab_Rango

    Sab_Rango

    Joined:
    Aug 30, 2019
    Posts:
    121
    Hey!
    1). I think, the point constraint, controls local Y position in the world. So then the new system do not conflict real car physics' Y and X local positions in the world.

    2)The normal force gives projection forces for Y and X position, to tell the car to Y,X velocities to stop or reflect the velocity to another direction.

    here, car moves in static land. The system just need to avoid collision interactions and re-direct car velocity or stop the car.

    No need for exchange energy with another rigid body.

    3) yes, it's

    ConstCar.png
     
    Last edited: Mar 8, 2021
  3. Alex33333333

    Alex33333333

    Joined:
    Jan 3, 2017
    Posts:
    11
    Thanks for your answer.
    I think general algorithm is:
    1.Create rigid body for the vehicle body and wheels.
    2.Use constraints (joints) to attach vehicle rigid body to the wheel's rigid bodies.
    3.Turn off collisions on the wheels.
    4.Cast collider from each wheel's center to the ground.
    5.Snap each wheel to the hit point.
    6.Next we need to do some calculations to get friction force on each wheel and apply final impulse on each wheel.

    So, yes, point-constraints move wheels along y-axis and result of this movement affects vehicle body position, because body and wheels are connected via joints.
    I want to clarify: I'm not writing my code from the scratch, I'm trying to covert my vehicle system from old physics to dots. So, I'm actually have all the required calculations. But I'm currently stuck on steps 5 and 6. These steps were implemented in my old system, using WheelCollider. I just call WheelCollider.GetGroundHit() and it gives me WheelHit structure. And after that I have the "normal force" (WheelHit.force). "Normal force" is the magnitude of the force being applied to the contact.
    So, now I don't have WheelColliders, and I'm very curious about "point-constraints" described in the video. I don't understand what is this point constraint and how can I access it in code. Is it unique Havok feature or the speaker just labeled it like that and this is just some manual calculations they implemented on their own?
    I can snap wheels to the hit points directly, without any constraints, but will it be the proper way to do it? And if I'll snap them directly how can I calculate "normal force", which, guys from the video get from "point-constraints".
     
  4. Sab_Rango

    Sab_Rango

    Joined:
    Aug 30, 2019
    Posts:
    121
    There are some vehicle demos in the physics samples.


    Assets\Demos\6. Use Cases\RaycastCar
     
  5. Alex33333333

    Alex33333333

    Joined:
    Jan 3, 2017
    Posts:
    11
    Yes, I know, but I can't find anything there. Raycast car is too simple.
     
  6. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Hi @Alex33333333 , Uncharted is using Havok SDK, which is also under the hood of Havok Physics in Unity, but the API in Unity variant is narrower. I think they were referring to "point constraints" in a sense of solver constraints (body A cannot go past the specified plane), not joints.
    Tagging @steveeHavok who might be able to help with some tips.
     
    Alex33333333 likes this.
  7. Alex33333333

    Alex33333333

    Joined:
    Jan 3, 2017
    Posts:
    11
    Hi, thanks for the answer. Yeah, looks like this feature just not implemented in unity. And big thanks for the link to Steve's profile here. I had already found his email he provide in one of the videos from Unite and was going to contact him. But it would be much more convenient to write him via the forum's messages.
     
  8. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    3) This one first as it is easy. Yes "Shape Cast" == "Collider Cast". The Havok SDK refers to Shape, however for some consistency we used 'Collider' for Unity Physics. They are the same thing though.

    1) Ultimately, a wheel is needing to stop the vehicle plowing through the ground.
    I'm guessing the 'normal force', well impulse really, is the change in velocity needed to stop (or slow with soft suspension) the movement of the chassis. Therefore, to get a hard stop, the change in velocity is going to have a magnitude equal to the relative velocity between two colliding bodies at the contact point, and a direction given by the contact normal.
    In Unity Physics, if you turn on CollisionEvents (set 'Collision Response' in 'Physics Shape Authoring' to 'Collide Raise Collision Events' then you can have an ICollisionEventsJob to get each event. Each CollisionEvent is going to have a Normal property to give direction. However, the 'collision' between two bodies is usually a surface made from from one or more contact points that are likely separated by some distance. So there isn't really a single collision impulse or an actual collision point.
    That said, the CollisionEvent.CalculateDetails utility function uses the raw solver information to generate more developer friendly data, such as an EstimatedImpulse from the collision. If you actually need a 'normal force' from a collision, then it would be this EstimatedImpulse multiplied by the Time.deltaTime * Normal.
    These collision details are not calculated automatically as there is an performance overhead and not every use-case cares.

    2) To be honest, I do not know what he means by the 'point constraint'. Ball and Socket Constraints are also sometimes called Point to Point Constraints. So it might mean that they are simply adding some Ball and Socket Constraints at points on the wheel supplied from the Collider Cast. That sounds nasty though so unlikely.
    As @milos85miki mentioned, he probably means a contact point in the collision manifold. In the C++ Havok SDK you can add in extra contact points though that's not currently possible in Unity Physics.
    If general collisions are turned of for a wheel, Then the approach could be somewhat faked by adding in a few static bodies under each wheel at positions and orientations defined by the collider cast. These bodies would have a simple plane or box collider and would only effect the wheels.


    So you could either we are talking about 2 options to replace the wheel collider.
    a) Wheels are represented by rigid bodies and constrained to the chassis rigid body. We are then dealing with collision events and/or messing with the contact jacobians (see the ModifyContactJacobians demo), or adding in extra 'ground' bodies under each wheel based on collider cast info.
    b) Not bother with rigid bodies for the wheels at all. Just get all the information you need from the use of the collider cast to apply the impulses to the chassis from the position the wheel center should be at (similar to the RaycastCar demo but a nice upgrade). You can use functions like PhysicsVelocity.GetLinearVelocity and pass in the contact point to get the relative velocity of the chassis at that point. This point velocity, plus the contact normal can be used to calculate suspension forces.
     
  9. Alex33333333

    Alex33333333

    Joined:
    Jan 3, 2017
    Posts:
    11
    Thanks a lot for your detailed answer Steve. I tried to find methods which can provide some additional contact details, but I could not guessed it can be provided by the job. (haven't dived so deep into Physics yet) I think I'll stick with variant a. I guess I can report the results in one or two weeks. (if anybody is interested)
     
  10. flyer19

    flyer19

    Joined:
    Aug 26, 2016
    Posts:
    126