I have a sphere with a rigidbody on it, and it moves to the right continously as I need it, but as it moves I want the space bar to be able to switch the gravity (so it either rides on the ceiling or on the floor), as it moves along to the right.
Please help, have been googling consistently for the past 3 hours.
Here is the code I have so far:
public class movement : MonoBehaviour {
public float movementSpeed = 10;
private bool haspressed;
void Start()
{
}
void FixedUpdate()
{
transform.Translate(Vector3.down * movementSpeed * Time.deltaTime);
if (Input.GetKeyDown ("space") && haspressed == true) {
transform.Translate (Vector3.right * movementSpeed * Time.deltaTime);
haspressed = false;
} else if (Input.GetKeyDown ("space") && haspressed == false) {
transform.Translate (Vector3.right * movementSpeed * Time.deltaTime);
haspressed = true;
}
}
}
Thank you sooo much!