Setting a value to 0 in a short time instead of instantly
Hi,
I'm trying to make some sort of 1'st person Flying simulator. I have the controls working (kinda), but when the player releases the control stick on the controller, the ship stops rotating immediately. How do I let it quickly slow down the rotation instead of instantly setting it to 0?
Code:
// Controller controlls
if (useController)
{
if (Input.GetKey(KeyCode.Joystick1Button0))
{
rb.velocity = transform.forward*thrustForce*Time.deltaTime;
}
horizontalRotation += Input.GetAxis("Horizontal") * horizontalSensetivity * Time.deltaTime;
verticalRotation += Input.GetAxis("Vertical") * verticalSensetivity * Time.deltaTime;
strafeRotation += Input.GetAxis("controllerBumpers") * strafeSensetivity * Time.deltaTime;
if (Input.GetAxis("Horizontal") == 0)
{
horizontalRotation = 0;
}
if (Input.GetAxis("Vertical") == 0)
{
verticalRotation = 0;
}
if (Input.GetAxis("controllerBumpers") == 0)
{
strafeRotation = 0;
}
}
Debug.Log(shipRotation);
transform.Rotate(shipRotation);
Answer by FortisVenaliter · May 13, 2016 at 08:29 PM
Check out the settings for that axis in the Edit->Project Settings->Input window. You can adjust the gravity variable, which determines how quickly it resets to zero.
Alternately, you can try some form of interpolation.
Problem is: I'm looking to do this with a controller. As such, gravity won't work... I do have found some sort of problem. Ins$$anonymous$$d of using
strafeRotation += Input.GetAxis("controllerBumpers") strafeSensetivity Time.deltaTime; for example, I could use strafeRotation = Input.GetAxis("controllerBumpers") strafeSensetivity Time.deltaTime;
But the problem with this is the rate at which the ship rotates now. It nearly doesn't. For this, I could add A LOT of sensitivity in code, but then the numbers would get really high. And for some reason, I try to keep the numbers a bit low.
I will try, however, with the high numbers. But if a better way is possible, I'd like to know.
But as with this, the ship will rotate as far as you push the stick. So if you release the stick, the ship will instantly stop rotating. How can I fix this? Will see if some form of interpolation could help.
Right, so you need to simulate an axis. Store a float, and interpolate it each frame with the actual axis value. That way it will float a little bit more than the stick alone.
Your answer
Follow this Question
Related Questions
How do you create decreasing health over time? 3 Answers
Thermometer-like object 0 Answers
Decreasing Light Source 0 Answers
Tool Durability if Hit any Collider 1 Answer