Hello, I’m in the middle of making a space simulator and i have all the spaceship controls working perfectly, Everything is smooth apart from when i “Roll” its too sudden, Is it possible to make it slowly build up rotate speed as i press the button then once released it will gradually slow down to a stop, like as if air is being forced out of the wings to stabilize the rotation. I’m just trying to make it seem as real to space as possible and this 1 tiny thing is holding me back,
Thanks.
function FixedUpdate(){
if(SystemStatus){
if (Input.GetKey ("d")){
transform.Rotate(0,0,- 1.0);
}
if (Input.GetKey ("a")) {
transform.Rotate(0,0,1.0);
}
You can add inertia to the controls using a “Lerp filter” - it’s a special trick with Lerp that smooths out the input signal, thus the ship will not start/stop rolling immediately. You should also use Time.deltaTime to have a predictable and framerate independent roll speed.
var rollSpeed = 60; // roll speed in degrees per second
var filterSpeed = 5; // how fast the filter follows the key
private var rollDir: float = 0;
function FixedUpdate(){
if (SystemStatus){
var rollCtrl = 0;
if (Input.GetKey("d")) rollCtrl = -1;
if (Input.GetKey("a")) rollCtrl = 1;
// rollDir is a smoothed version of rollCtrl
rollDir = Mathf.Lerp(rollDir, rollCtrl, Time.deltaTime * filterSpeed);
// use Time.deltaTime to have a framerate independent roll speed
transform.Rotate(0, 0, rollDir * rollSpeed * Time.deltaTime);
}
}