- Home /
Inverted gravity makes character walk on the wrong side of the platform
I am very new to Unity and have got a scene that I am supposed to change. I'm trying to make a game like gravity guy, but whenever I try to change back to "regular" gravity, my character starts walking on top of the "top floor" instead of moving back down... I found a couple of solutions on the internet that I could not get to work. Any advice would be appreciated.
public Vector3 jump;
public float jumpForce = 2.0f;
public float jumpSpeed = 1.0f;
private Vector3 moveDirection = Vector3.zero;
public bool isGrounded;
Rigidbody rb;
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
// get the third person character ( this should never be null due to require component )
character = GetComponent<ThirdPersonCharacter>();
StartCoroutine(Choreography());
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("down"))
Physics.gravity *= -1;
if (Input.GetKeyDown("down"))
transform.Rotate (transform.rotation.x,transform.rotation.y,transform.rotation.z-180);
if (Input.GetKeyDown("down"))
moveDirection.y = -jumpSpeed;
}
void OnCollisionStay()
{
isGrounded = true;
}
IEnumerator Choreography()
{
yield return new WaitForFixedUpdate ();
//walk forward
float startTime = Time.time;
float duration = 120f;
while (Time.time < startTime + duration) {
character.Move (Vector3.forward, false, false);
yield return new WaitForFixedUpdate ();
}
}
Answer by Linkthehylian04 · Jun 19, 2017 at 07:29 PM
You seem to have a version of gravity in your script. Did you make sure you turned off "Use Gravity" in the Rigidbody component? Since you have incorporated a version of your own gravity in this game, you need to make sure the default gravity normally used in Unity games is turned off.
Answer by kasoko · Jun 19, 2017 at 07:56 PM
Then it doesn't work at all... Is there a way I can make the character jump when it's upside down so it will move back down as the gravity is inverted in the same instant?
Your answer
Follow this Question
Related Questions
Character ShopSave 0 Answers
Changing gravity direction... 5 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
3D Gravity towards one object 3 Answers