I’m new to C# and Unity in general so please excuse me for not knowing most of the terms. I’m having trouble getting my players movement control to work right. My forward speed is faster than my back speed so when I press both keys at once, the character will still move forward only a bit slower.
I want to be able to press forward and still have the up and down buttons to work the same but not allow the back button to work until I let go of the forward button… and vice-versa.
public float forwardSpeed = 7;
public float backSpeed = 4;
public float dropSpeed = 4;
public float riseSpeed = 5;
void Update () {
if(Input.GetKey("up")) {
transform.position = transform.position + (transform.up * riseSpeed * Time.deltaTime);
}
if(Input.GetKey("down")) {
transform.position = transform.position - (transform.up * dropSpeed * Time.deltaTime);
}
if(Input.GetKey("left")) {
transform.position = transform.position - (transform.right * backSpeed * Time.deltaTime);
}
if(Input.GetKey("right")) {
transform.position = transform.position + (transform.right * forwardSpeed * Time.deltaTime);
}
}