- Home /
adding a gravity system to character controller
I have a character controller, and i need it to not float in the air when it moves off a high platform. i want it to fall down to the ground. however i dont want it affected by gravity necessarily, so i dont want controller.SimpleMove. i want something that will keep pushing it down, without slowing my character when it moves (as controller.SimpleMove does. the stuff in comments are tests to find different solutions. heres my script:
private var controller : CharacterController;
var speed : float = 4f;
public var woman : Transform;
var Gravity = 10;
public var Length : float = 10;
function Start () { controller = GetComponent(CharacterController);
}
function Update () {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = woman.TransformDirection(moveDirection);
moveDirection *= speed;
controller.Move(moveDirection * Time.deltaTime);
//var up = transform.TransformDirection(Vector3.up);
//Debug.DrawRay(transform.position, -up Length, Color.green); //if(!Physics.Raycast(transform.position, -up, Length)) { //Debug.Log("Hit"); //controller.transform.Translate(0, -Gravity Time.deltaTime, 0);
}
}
@script RequireComponent(CharacterController)
Answer by Waz · Jul 06, 2011 at 10:30 PM
The CharacterMotor script does this stuff, including gravity.
Your answer
Follow this Question
Related Questions
Gravity for my AI 0 Answers
How reliable are isGrounded checks? 1 Answer
if (controller.isGrounded == false) (for more than) public int time = 1.0F; // do stuff 2 Answers
Shifting gravity from the ground to the wall. 2 Answers
Rpg style movement help. 2 Answers