Hovercraft Physics Problems

I’ve written my own hovercraft physics, however I can’t seem to get it to work. I have Ray Position game objects that I place on different corners of the vehicle to dictate where the raycasts will go. These positions are then used to create the raycasts (going down), then determine where to add force on each corner of the object. I know I have nothing rotating or moving it forward, but what am I missing to get it off of the ground?

EDIT: Okay I figured out how to get it off of the ground with help from Wolfram, now it rocks and flips over a lot how can I fix that?

#pragma strict

var vehicleSpeed = 20;
var rotationSpeed = 10.0;
var airborneForce = 5.0;
var offgroundHeight = 10.0;
var startRotation : Quaternion;
var startPosition : Vector3;
var rayPos : GameObject[];

function Start () {
	
	rayPos = GameObject.FindGameObjectsWithTag("RayPos");
	startRotation = transform.rotation;
	startPosition = transform.position;
	
}

function Update () {
	
	var down = transform.TransformDirection (-Vector3.up);
	
	var forwardForce : float = Input.GetAxis ("Vertical") * vehicleSpeed;
	
	var	flight = transform.TransformDirection (Vector3.up * airborneForce);
	
	rigidbody.AddForce (transform.forward * forwardForce);
	
	if(Input.GetAxis ("Horizontal")){
		
		var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
		transform.Rotate (0, rotation, 0);
		
	}
	
	if(Input.GetButtonDown("Jump")){
		rigidbody.drag = 50;
	}else
		
	if(Input.GetKeyDown("left ctrl")){
		transform.rotation = startRotation;
		transform.position.y += 2;
		rigidbody.drag = 50;
	}else
	
	if(Input.GetKeyDown("r")){
		transform.rotation = startRotation;
		transform.position = startPosition;
		transform.position.y += 2;
		rigidbody.drag = 50;
	}else
		
		rigidbody.drag = 0;
	
	 if (Physics.Raycast (rayPos[0].transform.position, down, offgroundHeight)) {
	 		rigidbody.AddForceAtPosition(flight, rayPos[0].transform.position);
	 }
	 
	 if (Physics.Raycast (rayPos[1].transform.position, down, offgroundHeight)) {
	 		rigidbody.AddForceAtPosition(flight, rayPos[1].transform.position);
	 }
	 
	 if (Physics.Raycast (rayPos[2].transform.position, down, offgroundHeight)) {
	 		rigidbody.AddForceAtPosition(flight, rayPos[2].transform.position);
	 }
	 
	 if (Physics.Raycast (rayPos[3].transform.position, down, offgroundHeight)) {
	 		rigidbody.AddForceAtPosition(flight, rayPos[3].transform.position);
	 }

}

a) you are applying a downwards force to the rigidbody, but you need to apply an upwards force. Don’t try to apply the “exhaust” from your hovercraft fans, apply the direction in which they would push your hovercraft: up.

b) note arrays start their count at 0, so if you have 4 objects tagged “RayPos”, you’ll need to access them using indices [0]…[3], not [1]…[4].

c) don’t use any Find*-functions in Update, they are extremely slow. Assuming the amount/identity of objects tagged “RayPos” doen’t change, do the FindGameObjectsWithTag() only once (i.e., in Start()). If the objects somehow do change, it might be a good idea to put the FindGameObjectsWithTag() in a separate function which is only called when they change.

EDIT: the script evolved while trying to solve all related problems, so the answer itself is rather outdated, but still contains hints to keep in mind. the rest of the answer is distributed in the comments :wink: