Slow Variable Decrease

hey, i'm trying to make a basic script that continually increase/decrease the variable Yaw while it's corresponding key is held down, and then slowly levels out to 0 when both keys are released.

function Update () { 
if(yaw > 0){
yaw = yaw-0.5;

} if(yaw < 0){ yaw = yaw+0.5; }

if(Input.GetAxis("Yaw") == 1){
yaw++;

} else if(Input.GetAxis("Yaw") == -1){ yaw--; } else{

}

}

this is all i've got so far, but instead of giving an increase, it only sets yaw at 1, 0, or -1. Also, the response time has plummeted, but all other scripts run at the right speed.

thanks in advance

Can you mark this as answered

–

1 Answer

1

To get continued calls from inputs being held down your going to want to use Input.GetKey(). Input.GetAxis only fires once, when the button is initially pressed. That is why your values are not incrementing.

Also when you increment values, you will want to multiply the incremental value(here represented by yawSpeed) by Time.deltaTime to get consisted timing.

if(Input.GetKey(KeyCode.LeftArrow)){ yaw+= yawSpeed * Time.deltaTime}

Please mark this as answered.

–

Thanks for the upvote cyclops, my downvotes will be reserved for the most deserved of dumb questions. ;)

–