Hi, i’m trying to make a vehicle hover a certain height above the ground, I’ve either made or found this script ( i haven’t worked on this for a while), which does sort of work but is not ideal as it just bounces around far too much
What i’m really trying to do is make a script which detects how far you are from the ground, and sets a deceleration for that, however i’ve only just started to learn js so how would you do this?
How could you make the force added a function of the change in distance between the vehicle and ground, up to a limited maximum value?
SO as it gets closer to its target distance, the amount of force applied is less so it doesn’t go over its target distance.
(current script)
#pragma strict
function Start () {
}
var hoverHeight : float = 10;
function Update ()
{
var ray = this.transform.position;
if (Physics.Raycast(transform.position, -transform.up, hoverHeight))
{
rigidbody.AddForce(0,100,0);
}
}