Incremental control input

Hi there - I’m only just starting out facing a huge learning curve so please be gentle with me :wink:

I’ve got a setup with throttle control on the w/s keys using rigidbody.AddRelativeForce to provide the motion. At the moment pressing ‘w’ gives forward motion pressing ‘s’ gives rearward motion.

What I would really like it to do is have a graduated throttle - say with values 1-10 that increase sustain. The longer a key is pressed, or the more times a key is tapped alters the throttle setting (with no reverse).

Here’s what I have at the moment:

// check Throttle input 
if (Input.GetButton ("Throttle")) 
{ 
flyForward = Input.GetAxis ("Throttle") * moveSpeed; 
flyForward *= Time.deltaTime; // adds consistency across varying framerates 
} 
 
// apply Throttle
    rigidbody.AddRelativeForce (-(flyForward), 0, 0);

Any clues or pointers would be greatly appreciated - unfortunately I’m sure there’ll be more questions to come :roll:

thanks

Tom

function FixedUpdate ()
{
   flyForward = Input.GetAxis ("Throttle") * moveSpeed;  
    rigidbody.AddRelativeForce (-(flyForward), 0, 0); 
}

Forces are already independent of framerate so no need to multiply by delta time.

You can use input axes for the slow acceleration. Simply make the gravity sensitivity values smaller.

Excellent - thanks Joachim, that’s got it on the right track the sensitivity gravity settings were far too high for what I needed.

Just have to figure out how to stop it going into reverse now :smile:

I have another stumbling block now, well a couple really :roll:

i have a plane flying around - controlled by analogue input. I have the controls being operated by forces being applied at the relative points on the airframe to make it move around…this is working fine.

At the moment when the throttle is killed, the plane stops dead - how can I make it continue using momentum?
This is the section of code I’m using at the moment

//***THROTTLE CONTROL***
//Tells thottle amount that range -1 to 1 is actually 0 to 1
flyForward = (((Input.GetAxis ("Throttle")/2)+ 0.5) * moveSpeed) ; 
// apply forward movement 
rigidbody.AddRelativeForce (-flyForward, 0, 0);

To follow on - I have control surfaces on the plane that I want to move proportionally with the analogue input (not continuous rotation)…what command can I use to make this happen…this is for visual benefit only.
I’m thinking that it should be able to fit in with this kind of idea:

transform.Find("Unity plane 02 [Rudder]").rigidbody.AddRelativeForce(0, -rudderRotate, 0);

where instead of adding a force, it applies a fixed rotation dependant on control input.

any pointers will be greatfully appreciated