Writing a simple script to rotate an object in direction of axis
I wanted to write a script that would rotate a transform to point in the direction given in the axis, either with mouse or joystick. I did accomplish this, but there's a tiny hiccup. As soon as the player no longer uses the thumb sticks/joysticks/mouse to rotate the transform in the wanted direction, the transform automatically returns to the original pointed direction. This is because in my script, it reads the axis as being close to zero. Here is my code:
if((Input.GetAxis("Mouse X") != 0) && (Input.GetAxis("Mouse Y") != 0)){ transform.forward = new Vector3(Input.GetAxis("Mouse X"), transform.forward.y, Input.GetAxis("Mouse Y")); }
Does anybody have a solution to correct this, so that when the player no longer wishes to rotate the transform, the transform remains rotated with forward direction as desired, instead of returning to place?
Note: I do want instantaneous rotation to the desired rotation, so as the make the transform point in a certain direction. I do not want progressive rotation unless it is very fast and stops once the desired rotation is established.