for reason character, when press or d (turn left or right controls) rotate intended. when let go of or d rotation continued applied (ie character keeps turning).
as far i'm aware there no functions being called touch player's rotation outside of input functions. on or d input, rotation applied character in direction (accessing value of getaxis direction). when input released (ie keys no longer being pressed, , getaxis returns '0') rotation should stop, function causes rotation no longer called. yet character still turns?
i'm @ loss why happening appreciated!
below snippets of code using;
public class playercontroller : monobehaviour { . . . private bool yaw = false; private float yawdir = 0.0f; . . . private void getinput() { if (input.getbuttondown("fwd")) { } else if (input.getbuttondown("back")) { } if ((input.getaxis("yaw") > 0 || input.getaxis("yaw") < 0) && input.getaxis("yaw") != 0) { yawdir = input.getaxis("yaw"); yaw = true; applynewheading(newheading); } else if (input.getaxis("yaw") == 0) { //applynewheading(0); yaw = false; yawdir = 0.0f; } } . . . private void applynewheading(float newheading) { if (yaw) { transform.rotate(0, yawdir * shipclasshandler.getmaxturnrate() * time.deltatime, 0); } }
have checked what's being returned input.getaxis("yaw")
:
is safe check floating point values equality 0?
your code reduced like:
if (!iszero(input.getaxis("yaw"))) { ... } else { ... }
where iszero()
suitable float-checking function.
Comments
Post a Comment