ok i have abandoned my quest to use the mouse scroll for my acceleration and deceleration as its just not reading it right. soooo here we go.
useing keyboard commands I have a button to accelerate and decelerate i can accelerate just fine works like a charm but instead of decelerateing i come to a compleate stop. here is my code. can some one please help me out here.
var flyingSpeed = 0;
var minThrust : float= 0;
var maxThrust : float = 100;
var Accel = maxThrust / 4;
function Update () {
if(Input.GetButton("Thrust")){
flyingSpeed = Accel + Mathf.Clamp(flyingSpeed, minThrust, maxThrust - Accel);
}
if(Input.GetButton("Decellerate")){
flyingSpeed = Accel + Mathf.Clamp(flyingSpeed, minThrust - Accel, maxThrust );
}
if(("Thrust")){
rigidbody.velocity = transform.forward * Time.deltaTime * flyingSpeed; //Apply velocity in Update()
}
}
fixed the problem works great now. if anyone is intrested i put together a fully functional copy that incorperates horizantal and vertical movement.
still needs some tweaking and i plan on adding a few things like roll and what not. that part of the script isnt mine. i borrowed it. so please feel free to use my script.
var flyingSpeed = 0;
var minThrust : float= 0;
var maxThrust : float = 1000;
var Accel = maxThrust / 4;
var turnSpeed = 10;
function Update () {
//Accelerate the ship useing the thrust button.
if(Input.GetButton("Thrust")){
flyingSpeed = Accel + Mathf.Clamp(flyingSpeed, minThrust, maxThrust - Accel);
}
//decelerates the ship till stop.
if (Input.GetButton("Decellerate")){
flyingSpeed = -Accel + Mathf.Clamp(flyingSpeed, minThrust +Accel, maxThrust );}
if(("Thrust")){
rigidbody.velocity = transform.forward * Time.deltaTime * flyingSpeed; //Apply velocity in Update()
// Turning commands.
if(Input.GetAxis("Horizontal") > 0.0){ //if the right arrow is pressed
transform.Rotate(0.0, turnSpeed * Time.deltaTime, 0.0 * Time.deltaTime, Space.World); //and then turn the plane
}
if(Input.GetAxis("Horizontal") < 0.0){ //if the left arrow is pressed
transform.Rotate(0.0, -turnSpeed * Time.deltaTime, 0.0 * Time.deltaTime, Space.World); //The X-rotation turns the plane - the Z-rotation tilts it
}
if(Input.GetAxis("Vertical") > 0.0){ //if the up arrow is pressed
transform.Rotate(-20.0 * Time.deltaTime, 0.0, 0.0);
}
if(Input.GetAxis("Vertical") < 0.0){ //if the down arrow is pressed
transform.Rotate(20.0 * Time.deltaTime, 0.0, 0.0);
}
}
}