Everyone has to make some of the stuff extremely harder than what it should be lol.
Have a script do something like
Void OnTriggerEnter (Collider col){
if(col.gameObject.tag == "Player")}
Physics.gravity = new Vector3(0,9.81f,0)
}
}
That should in theory reverse Gravity, you may have to do 18 or whatever as -9.81 + 9.81 = 0.
Then have the script access your player
Have a bool on your player called
public bool ReverseGrav = false; // This is if we are upsidedown.
Lets say your Player script is called Controller (just to simplfy it for me lol)
Go back to your OnTriggerEnter script that you made first.
Make another variable called
Public Controller controller; // The first Controller is the //name of your script the second is the Variable name.
Now have this bool under your Physics and put
controller.ReverseGrav = true;
DO A SAVE AND ADD THE TRIGGER SCRIPT TO THE AREA YOU WANT TO FLIP GRAVITY AND ADD CONTROLLER TO YOUR PLAYER, NOW GO TO THE TRIGGER ZONE AND ADD YOUR PLAYER INTO THE INSPECTOR FOR THE CONTROLLER SPOT.
Now lets finish the last little bit of code.
Go to your CONTROLLER script that we made.
Now in UPDATE put
if(ReverseGrav){
transform.rotate(180.0.0);
}
That should in theory work, because we Reversed Gravity and rotated the player to from now on be flipped over, shouldn’t be too too hard to finish the rest to make him flip back…
(CODE IS UNTESTED) But should work.
Hoppe that helps!
Sorry for late answer. I forgot to mention that I'm making a 2d game. So flipping the world would not work. I want the character to walk in the top side of the window if the gravity is flipped.
– SveinEvenRotating the world would work in 2D. I'd only do it if you have a 2D Character Controller that you don't want to modify and that doesn't handle gravity flipping.
– robertbu