- Home /
Gravity not functioning properly?
In my game I'm switching gravity round so the user can walk on the ceiling. To move and jump I'm using the standard "2D Side Scroller" code from the assets folder. My problem is when I flip gravity around the character moves along the ceiling VERY slowly and cannot jump so it seems to me that gravity is pushing down WAY too hard on it. Does anyone know how I can fix this? The code I use to invert gravity is:
function OnGUI () {
if (GUI.Button (Rect (0,0,50,50), "Up")) {
Physics.gravity = Vector3 (0, 1.0, 0);
}
if (GUI.Button (Rect (50,0,50,50), "Down")) {
Physics.gravity = Vector3 (0, -1.0, 0);
}
}
Thanks in advance!
Answer by StephanK · Jun 20, 2010 at 10:24 AM
The switching gravity part should be ok although normally gravity is 9.81 not 1. The problem is probably in the moving code. I guess the jumping code works independently from the direction of gravity and assumes that by jumping you mean "move in Vector3.up direction, which won't work if you're upside down.
Ahhhh thanks. The problem I'm having is with "isGrounded", it isn't called when the ceiling is touched because it doesn't realise its the new floor. Any idea how to solve this?
Your answer
Follow this Question
Related Questions
Constant force 2 Answers
AddForce forward also adding downward force 0 Answers
Player movement with Rigidbody only, gravity not working at all. 0 Answers
how to create buttons using iphone look and feel?? 2 Answers
Zero Gravity like Physics? 1 Answer