- Home /
How do you change the direction of gravity?
I'm looking to make a multiplayer game where each character has a different gravitational pull. For instance, player 1 walks on the floor, while player 2 walks on the ceiling, player 3 walks on the east wall, etc. But I just can't seem to figure out how to change the direction of gravity on any particular character. Any help is appreciated.
Answer by oliver-jones · May 12, 2014 at 04:18 PM
You can change the Vector3 direction of the gravity in Editor > Project Settings > Physics.
In your case, you want the Y axis to be positive 'something'. 9.81 if you want real world physics - but going the other way.
Problem is this affects the entirety of the world physics... However I want several different players to each have their own direction of gravity. Pretty sure if I adjust these settings I'm just going to have every player walking across the ceiling.
You can set gravity to -ve on a rigid body. This give you two options. Otherwise its disable gravity and custom addforces
Answer by Jeff-Kesselman · May 11, 2014 at 09:32 PM
The short answer is, you don't use Unity's world-gravity.
You code a gravity vector for each object in a script and, in the script's FixedUpdate call back, you apply the vector times the elapsed time as force to your object.
It appears gravity is controlled by the character controller. So does that mean I need to write my own character controller or can I either adapt the one provided by unity to do it, or disable gravity in the character controller and write a gravity script?
Yes, Character controllers don;t use the pHysics system. They do all their own calculation.
Unfortunately they aree one of the few parts of the system that are not implemented as a script so you cannot modify theirs.
Either you writ your own OR you try writing a secondary script that applies forces to balance the forces being supplied by the character controller.
Character controllers are basically evil. They are black boxes with their own behavior that is not necessarily fully documented. I always write my own control logic to avoid the pain of having to fight with them.
You need to write your own, the Unity CharacterController gravity is not tweakable
Your answer
Follow this Question
Related Questions
How to make a camera work in this circumstance. 1 Answer
Find closest transform 1 Answer
Database connection FPS game? 0 Answers
Problem with identifying players in network 1 Answer
AudioMixer Snapshot Problem 1 Answer