- Home /
Gravity character controller
Does a character controller need a script to have gravity ? or should an object with a character controller attached fall down until it hits something ? here is the script that I am using, it worked fine with a rigidbody and character controller attached - until I made some changes and then unity crashed, my sphere doesn't fall with a character controller attached ??
var speed = 0.15;
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
var movement = Vector3(Input.GetAxisRaw("Horizontal"),0 ,0);
movement *= speed;
if(controller.isGrounded){
controller.Move(movement);
}
}
Answer by torrente · Jul 31, 2012 at 11:24 PM
Hey Will,
The prebuilt character controller does not have any sort of built in gravity, you would have to program that in yourself. However, I do want to point out that there is a variable built in called isGrounded which will check if the bottom of the controller is touching something.
I'd also add that real world physics seem to take away from a player's ability to jump, since so many games seem to allow the player to jump like 15 feet up, so I "defy" physics when setting up my character jumps. Best way to get the jumping done is to run a test and stick with values that feel good.
Your answer
Follow this Question
Related Questions
CharacterController.Move uses gravity even though it shouldn't 1 Answer
Character floats upward when looking up and down 0 Answers
Problem with gravity and character controller 1 Answer
Character Controller walking on the inside of a cylinder. 0 Answers
How to rotate a Character Controller on the X or Z axis ? (Not for movement) 0 Answers