Flying script needs stop button

Hello all!! In attempting to make a jetpack script, I found that a flying script was the best option because I could make it work and control where I was in 3d space. My issue now is that it is not possible to stop, I need a button that instantly stops the force. I am using unity 2.6 as it has to be compatible with an old game. I have taged my camera as Player, I have mouselook, ridgid body (with no gravity), and constant force on the oject as well as my flying script. The z button section was my attempt to make a stop button but it does not work. Any and all help would be apreciated thanks!!!

Here is my script

private var pilot : Rigidbody;
var thrustForce = 100;

var invertPitch : boolean = true;
var invertYaw : boolean = false;
var sensitivity : float = 1.0;

function Start ()

if (Input.GetKeyDown(“w”))
{
SetThrust(500);

}

if (Input.GetKeyUp(“w”))
{
SetThrust(0);

}

if (Input.GetKeyDown(“s”))
{
SetThrust(-300);

}

if (Input.GetKeyUp(“s”))
{
SetThrust(0);
}
if (Input.GetKeyDown(“z”))
{
SetThrust(0);
}
}

function SetThrust ( thrustForce : int)
{
pilot.constantForce.relativeForce = Vector3.forward * thrustForce * sensitivity;
}

Can you disable physics for the object temporarily? I think this would cause any simulations related to force to stop.

Thanks thats a good idea! I acatualy found a non scripting workaround by adding angular drag to the ridgid body, it will drift a little, then come to a stop. Its a great effect and I love it :slight_smile: here is the final version of the script for anyone with a similar issue

private var pilot : Rigidbody;
var thrustForce = 3;

var invertPitch : boolean = true;
var invertYaw : boolean = false;
var sensitivity : float = -1000;

{ function Start ()
}
if (Input.GetKeyDown(“w”))
{
SetThrust(5);

}

if (Input.GetKeyUp(“w”))
{
SetThrust(0);

}

if (Input.GetKeyDown(“s”))
{
SetThrust(-3);

}

if (Input.GetKeyUp(“s”))
{
SetThrust(0);
}

}

function SetThrust ( thrustForce : int)
{
pilot.constantForce.relativeForce = Vector3.forward * thrustForce * sensitivity;
}

I set the angular drag to 3 for my purposes but you can set it for any effect that you would like. This is a script that I edited and simplifyed from the original by PoZo on unity answers (link)
Thanks for the help all on this post and my older post trying to solve a similar issue!

There are some compiling errors that I am not advanced enough to fix, but the script works fine even with them for me

It didn’t compile because the first part needs to be
function Start () {

if (Input.GetKeyDown(“w”))
{
SetThrust(5)

not

{ function Start ()
}
if (Input.GetKeyDown(“w”))
{
SetThrust(5);

it’s just a bracket issue :slight_smile:

still this script doesn’t make me fly :S
i disabled my charactercontroller scripts and FPS script and then I added rigidbody to my character, but this still won’t make me move at all. am I missing something