C# - Wipeout style Hovercraft effect

Greetings guys ,
I’ve been trying to archieve a hovercraft effect like shown in this video below for quite some time now : Unity3D HoverCraft test - YouTube
i want it to stay on the ground and be aligned to the surface below it and not go too far away from it but i can’t get it to stay on the ground no matter what i try . it either flips over or it goes flying and takes ages to come back down. i’m using a rigidbody so i can’t align it to the ground normal directly using the transform class . Please answer if you have any idea how to recreate this effect i’ve been stuck on this one for a long time and it’s getting on my nerves

There’s a buyonacy script designed for boats and other floating objects on water over on the forums, maybe it can serve as the base for your own script.

To keep the craft aligned to the ground at all times, ust cast a ray downward (in world space) and slowly rotate the craft towards the normal vector of the surface the ray hit.

private Quaternion rotCur;
Ray ray = new Ray(transform.position + Vector3.up * 1.0f, -Vector3.up);
	RaycastHit hit;
void Update() {
if(Physics.Raycast(ray, out hit) == true) {

	rotCur = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;

}

transform.rotation = Quaternion.Lerp(transform.rotation, rotCur, Time.deltaTime * 5);
}

Based on how that vehicle behaves, I’d hazard to guess they are not using “pure” physics to drive its behavior. It’s more likely a carefully tailored simulation specifically designed to achieve these effects.

That’s not to say you can’t re-create the behavior with Unity’s physics sim, but you should not expect the task to be simple.

I observe two distinctive behaviors in that video: self-righting, and hovering-suspension. These should be treated as separate-but-equal behaviors.

I’ve never done this, but my first thought WRT using Unity rigidbodies to duplicate the effect is:

Have several feelers (raycasts) in the “down” direction of the craft’s belly, and several “down” in world space, cast from the same points. (nose, tail, wing tips). Comparing the hit.normal of the “belly out” feelers to the “world down” should give you useful data about the terrain beneath the craft and the craft’s orientation relative to a flat plane. You can use this data to scale the forces you apply “up” from each point (AddForceAtPoint). Also, the distance of the hits on both sets of feelers will help drive “upward” force to produce the lazy suspension effect.

The self-righting behavior might apply the torque necessary to suggest a “belly level with terrain below me” orientation depending on what the feelers are reporting, so that you only self-right when necessary.

I guess a third need emerges here; maintaining position. On an incline, these two behaviors alone will encourage the craft to “slide down” hills. This is a complicated desire, I’m afraid. Honestly if I could, I think I’d avoid using rigidbodies for this task altogether. These behaviors are not physically realistic in the first place.