# Rotation not working properly(3D)

Basically I was trying to rotate the player 180 degrees around the z-axis to correspond with the gravity change that happens when you hold down two buttons. The result I got from this script is that the player will rotate, but then the gravity wouldn’t shift, and when I’d try to shift gravity again, it would shift, but then the rotation would be off. Here is the script that I used:

``````//Movement
float moveSpeed = 3000f;
float x, z;
float jumpHeight = 5f;

//Gravity
public float gravityForce = 10f;
float gravMultiplier = 1f;

//Random Stuff
public Rigidbody rb;

void Start()
{
rb = GetComponent<Rigidbody>();
}

void Update()
{
x = Input.GetAxis("Horizontal");
z = Input.GetAxis("Vertical");

if(Input.GetKey(KeyCode.Mouse2))
{
ShiftGravity();
}
}

void FixedUpdate()
{
//Movement
rb.AddForce(Vector3.forward * z * moveSpeed * Time.deltaTime);
rb.AddForce(Vector3.right * x * moveSpeed * Time.deltaTime);
}

private void ShiftGravity()
{
if (Input.GetKeyDown(KeyCode.W))
{
gravMultiplier *= -1;
Physics.gravity = new Vector3(0, gravityForce * gravMultiplier);
RotationFromGravity();
}
}

private void RotationFromGravity()
{
transform.eulerAngles = new Vector3(0, 0, 180);
}
``````

}

@BDDC

Hello!

This is an easy way to find the rotation of an object in the X-axis. it is a very simple and easy code.

``````float x;
void Update ()
{
x += Time.deltaTime * 10;
transform.rotation = Quaternion.Euler(x,0,0);
}
``````