I really hate being a burden, especially when I don’t know what exactly to do in this case, but I’m not sure what to do here. In brief, what I’m trying to do is alter my control script (which is already a mess of code snippets taken from various online sources) to allow the player to select about 6 speeds (Reverse, Stop, 1/4, 1/2, 3/4, and Full.) while having to only press the button once. (Bridge Commander’s control scheme is a perfect example of this.) So far I’ve managed to program the exact speeds that I want and I’ve successfully bound them to the buttons, but I have no idea how to maintain those speeds when I let go.
public float xFactor = 70f;
public float yFactor = 150f;
public float zFactor = 3f;
public float AmbientSpeed = 100.0f;
public float RotationSpeed = 200.0f;
void Update()
{
var x = Input.GetAxis("Horizontal") * Time.deltaTime * xFactor;
var z = 0.5f;
var y = Input.GetAxis("Vertical") * Time.deltaTime * yFactor;
if (Input.GetKey(KeyCode.Keypad0))
z = Time.deltaTime * 0;
if (Input.GetKey(KeyCode.Keypad1))
z = Time.deltaTime * 50;
if (Input.GetKey(KeyCode.Keypad2))
z = Time.deltaTime * 100;
if (Input.GetKey(KeyCode.Keypad3))
z = Time.deltaTime * 150;
if (Input.GetKey(KeyCode.Keypad4))
z = Time.deltaTime * 200;
if (Input.GetKey(KeyCode.R))
z = Time.deltaTime * -50;
transform.Rotate(y, 0, 0);
transform.Translate(0, 0, z);
transform.Rotate(0, x, 0);
Quaternion AddRot = Quaternion.identity;
float roll = 0;
float pitch = 0;
float yaw = 0;
roll = Input.GetAxis("Roll") * (Time.deltaTime * RotationSpeed);
pitch = Input.GetAxis("Pitch") * (Time.deltaTime * RotationSpeed);
yaw = Input.GetAxis("Yaw") * (Time.deltaTime * RotationSpeed);
AddRot.eulerAngles = new Vector3(-pitch, yaw, -roll);
GetComponent<Rigidbody>().rotation *= AddRot;
Vector3 AddPos = Vector3.forward;
}
Can anybody lend me a hand here?