- Home /
How to rotate back and forth on the X axis?
I'm using the below code to simulate a weapon sway. It should rotate on both X and Y axis but only seems to work on Y.
float verticalSwayAmount = 10;
float horiztonalSwayAmount = -10;
float xSwaySpeed = 5;
float ySwaySpeed = 2;
float x = 0, y = 0;
y += verticalSwayAmount * Mathf.Sin(ySwaySpeed * Time.time);
x += horiztonalSwayAmount * Mathf.Sin(xSwaySpeed * Time.time);
m9.transform.Rotate(new Vector3(x, y, 0) * Time.deltaTime, Space.Self);
How can I get it to rotate back and forth on the X axis as well?
Comment