I am trying to have a sphere rb rotate based on horizontal and vertical input. But - I want to reset the local axis when no input is being pressed. Use case:
sphere is rolled 90 degrees to the right. all buttons are released. When user holds down up or W I want the ball to basically rotate forward, but now its rotating right since it’s still based on the original rotation axis, not the updated on. (not sure if this makes sense or not, it’s tough to explain)
here’s the code I have so far:
private var h : float = 0;
private var v : float = 0;
var RotateSpeed = 2;
function Update () {
v = Input.GetAxis("Horizontal") * Time.deltaTime * RotateSpeed;
h = Input.GetAxis("Vertical") * Time.deltaTime * RotateSpeed;
transform.Rotate(h,(v * -1),0);
}
how can I reset the rotational axis once the inputs have stopped?
if (h == 0)
transform.localrotation.y = 0;
if (v == 0)
transform.localrotation.x = 0;
doesn’t seem to work.