- Home /
Question by
lixpoxx · Apr 18, 2014 at 08:47 AM ·
charactercharactercontrollercontrollerjumpgrounded
Let Character Controller jump.
Hello. The game I'm working on only requires jumping. I'm using a character controller to do so. This is my script:
function Update(){
var controller : CharacterController = GetComponent(CharacterController);
if(Input.GetButton("Jump")){
if (controller.isGrounded){
transform.Translate(Vector3.forward * jumpSpeed * Time.deltaTime);
}
}
I tried everything, but my player does't seem that he wants to jump. Please help me!
Comment
Answer by Loius · Apr 20, 2014 at 06:20 AM
You have to handle gravity. What you're doing is teleporting (Translate) the object up by approximately 0.001 meters for one frame.
var gravity : float = 0.0f;
function Update() {
gravity += 9.81 * Time.deltaTime;
if ( controller.isGrounded ) {
gravity = 0;
if ( Input.GetButton("Jump") ) {
gravity = -jumpSpeed;
}
}
controller.Move(movementVector - Vector3.up * gravity);
}
Your answer
Follow this Question
Related Questions
Let Character Controller jump. 0 Answers
How to fix a infinity jump? 1 Answer
Custom Character Script Allowing Movement in the Air? 0 Answers
Rigidbody character controller issues 0 Answers