# How to face Hovercraft physics

Hi, I’m trying to get a smooth and fluid physics for an hovercraft race game, something similar to this:

I writed a script for that but it wasn’t very smooth and I decided to restart it with another perspective.

What I tried for now was a rigidbody with gravity enabled and using raycast check the collision with the ground and apply a Vector3.up which keeps the distance with the ground.

The problem is that when I go forward and detect a ramp or a hill it’s really slow on going up.

My question is how to get a good behaviour with an hovercraft?

Also when turning I want the hovercraft to rotate to the side a little, would I need to do this with animations or should I rotate it on the local axis and use world axis for the movement?

I’m a little messed so if you need more information I will provide it.

Regards.

I’m kindof reluctant to tell you this information since i’m also doing a hovercar racing game but maybe it can be improved. So here is the script i used to achive a really good hovering effect, just not that easy to apply to exotic vehicles.

``````	public List<Transform> HoverPoints = new List<Transform>();
public float HoverHeight = 7;
public float HoverForceFront = 200;
public float HoverForceBack = 400;
void FixedUpdate ()
{
//Lift
for(int i=0; i < 4; i++)
{
RaycastHit Hit;
if(i >1)
{
if(Physics.Raycast(HoverPoints_.position, HoverPoints*.TransformDirection(Vector3.down), out Hit, HoverHeight))*_
``````

thisRigidbody.AddForceAtPosition((Vector3.up * HoverForceBack * Time.deltaTime)* Mathf.Abs(1-(Vector3.Distance(Hit.point, HoverPoints_.position)/ HoverHeight)), HoverPoints*.position);
if(Hit.point != Vector3.zero)
Debug.DrawLine(HoverPoints.position, Hit.point, Color.blue);
}else*

* {
if(Physics.Raycast(HoverPoints.position, HoverPoints.TransformDirection(Vector3.down), out Hit, HoverHeight))_

thisRigidbody.AddForceAtPosition((Vector3.up * HoverForceFront * Time.deltaTime) Mathf.Abs(1-(Vector3.Distance(Hit.point, HoverPoints_.position)/ HoverHeight)), HoverPoints*.position);
if(Hit.point != Vector3.zero)
Debug.DrawLine(HoverPoints.position, Hit.point, Color.red);
}
if(Hit.point != Vector3.zero)
isGrounded = true;
else*

* isGrounded = false;
}
}
It uses four points that you define in the inspector that act as points of lift, it applys a weak and strong force on the front/back to help balance vehicles, it’s also set up in a way that prevents the vehicle from sliding down ramps. thisRigidbody is a private variable that holds an instance of the gameObject’s rigidbody component.
This is a [1] of it in action, with a bit of other stuff.
I also made a hovercraft script that used a character controller that slid across the ground, it’s a but easier but a lot more limiting here is a [2] of that.

Alucard i just watched video 1 it was great, although it was difficult to listen as he was not clear about the mechanism used… he used quaternion for rotation, so the craft doesnt have rigidbody physics, and what did he do with the 4 corners of the craft??? measure height only? i didnt get it.

also… wanted to mention that hovercraft is same as having car with invisible wheels, and some suspension… to prevent bouncing as crazy, reverting to car with invisible wheels mode could be pretty handy.

@TheDarkVoid You should add a center of mass variable to the code.

public Transform CenterofMass;
public bool isGrounded;
// Use this for initialization
void Start () {
thisRigidbody.centerOfMass = CenterofMass.position - thisRigidbody.position;
Debug.Log(CenterofMass.position - thisRigidbody.position);
}

The key is to use damping. Simply apply a force linear to the vertical velocity in the opposite direction.