- Home /
The question is answered, right answer was accepted
Why my character wont jump???
Code:
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var AirSpeed : float = 0.25;
var FireParticle : GameObject;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
animation.CrossFade("Idle");
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0,Input.GetAxis("Horizontal"),0);
if(Input.GetAxis("Vertical")){
animation.CrossFade("Run");
animation["Run"].speed = Input.GetAxis("Vertical")*3;
}
moveDirection = Vector3(0,0,Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (controller.isGrounded) {
if (Input.GetKey(KeyCode.Space) && controller.isGrounded) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
Answer by VIPINSIRWANI · May 19, 2014 at 09:30 AM
Hi Once replace some line of your code and try may it work
if (controller.isGrounded) {
Debug.Log("Check character is On Ground...");
if (Input.GetKey(KeyCode.Space) {
moveDirection.y = jumpSpeed;
}
else
moveDirection.y -= gravity * Time.deltaTime;
I'm just gonna add that Get$$anonymous$$eyDown might work better, then Get$$anonymous$$eyRelease (or is it Get$$anonymous$$eyUp?) to check when you released it for a premature drop, whenever I've used Get$$anonymous$$ey for jumps personally its opened the door to an infinite height of jumps.
Now jumps but jump is very laggy,just moves position for the value nothing smoothly.
Follow this Question
Related Questions
Addforce to create a gliding effect? 2 Answers
Translation of an object 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do you make a characterController jump automatically when it reaches the edge of a platform? 0 Answers
How do I fix my player jumping code? 2 Answers