How to replicate these physics in Unity? (example video)

PS: I miss being able to delete threads and change thread titles… I hate cluttering up the forums. This thread was originally about something else that I figured out, but I’ll reuse the thread.

Ok, so I’m creating a prototype for a wacky game with a vehicle – I’m using wheel colliders, but they don’t seem to apply motortorque when upside down. I guess this isn’t a very common situation to see in a game… imagine a rollercoaster upside down – the coaster part is bellow the track, but the wheel is above the track preventing them from falling – if that wheel spins, they move. I need it to work both ways.

Am I correct in understanding this? In example A, the ray cast downward detects road and will be able to apply motortorque. But in example B, the ray doesn’t detect anything so no motortorque, but the wheel is obviously still contacting something visually and should have an effect.

So what should I do instead? Some way to dynamically change local rotation of wheel collider? Or should I not use wheel colliders and come up with my own solution – any links to help me get started with that?

Did a test to confirm it’s not returning anything for GetGroundHit when upside down

You could check for collisions, get the contact point, and rotate so that the local “down” points towards it.

Untested, just an idea I had upon reading this.

You should be getting an OnCollision event from the wheel colliders if they are in contact with the “track” or ground, shift the direction/rotation of the raycast toward the track based on collision.

Alternatively, you could use a Physics.SphereCast, instead of a directional raycast to detect the track/ground.

Cheers,

Galen

I’ll have to see how that would affect my joint setup and the rest of the vehicle, but ideally the solution bellow ends up working out…

Yeah but as far as I know, wheel collider hides it all behind the scenes. I’ve been playing around with using yoggy’s car/wheel stuff so that I have complete control, but I’m getting stuff like

“transform.localRotation assign attempt for ‘Graphic’ is not valid. Input localRotation is { NaN, NaN, NaN, NaN }.
UnityEngine.Transform:Rotate(Single, Single, Single)”

I opened up his example project in U3 – worked fine – did some work on it in that project to get it doing what I needed and then moved it into my project as a package, but now I get these errors.

Ah – error was caused by having some values set to 0 when bringing yoggy’s stuff to my project.

Basically got the wheel forces figured out. Now to try and make a very springing suspension…