- Home /
Custom Gravity CharacterController
I am working on a project in which we have a character moving around an Escher like space. The game is first person and the default character controller is actually almost perfect. The issue is that we need to change the orientation of the avatar so that it would be walking around the on the wall or the ceiling.
Currently we are rotating the entire environment and leaving the avatar orientation the same. This is causing issues with Unity's static batching, so we are again trying to figure out a way to rotate the player.
Question 1: Can anyone suggest an easy way to script around the default CharacterController so that we can change the direction of gravity?
Failing that I am looking for a good/free-to-use character controller script which I might modify rather than writing one from scratch. I found this one:
but it is really glitchy and we don't actually want a physics based controller.
Question 2: Can anyone suggest a character controller script that simply duplicates the built in CharacterController? (Bonus points for JS but CS will also be fine)
----------------- EDIT -----------------
Getting global gravity to change is fairly easy. I am looking for a way to rotate the character controller So that the camera orientation and the movement will match the changed gravity.
I made it here, but its my own First Pirson Controller with Capsule-collider and Rigidbody attached. link text
Answer by ByteSheep · Mar 05, 2012 at 02:04 AM
You can edit unity gravity using:
Physics.gravity = Vector3(0, -1.0, 0);
To change directions you can set x, y or z to a value - the vector function looks like this:
Vector3(x, y, z);
So if you set gravity to:
Physics.gravity = Vector3(-1.0, 0, 0);
Then the character etc will fall to the left or right.
Here's the unity documentation: http://unity3d.com/support/documentation/ScriptReference/Physics-gravity.html
I'd advise to always check there ;)
This will be useful if we decide to include rigidbody objects in the environment but my concern is getting the orientation of the character controller to change.
Changing the global gravity either by script or via the physics manager menu does not change the way the CharacterController component behaves at all. It appears that "up" is hard coded into the 'CharacterController' component.
I will edit the question to try and be more precise.
Answer by eneroth3 · Jan 10, 2019 at 10:01 AM
I am having the same problem. From what I can see the "gravity" direction seems to be hard coded within the character controller itself. I'm currently trying to re-create its functionality as a rigidbody controller, but if there is a way to get the character controller to use a custom vertical direction, I'd be happy to know.
Your answer
Follow this Question
Related Questions
Gravity for my AI 0 Answers
How reliable are isGrounded checks? 1 Answer
Rpg style movement help. 2 Answers