Why won't my character jump? [JS]
I found a script on the Unity Scripting Reference that was very useful for my FPS system. It allowed me to make my character move forwards, backwards, left, and right using the Horizontal and Vertical axes. I then added in a lot of things like jumping, looking around, and loading a new map.
I've pretty much abandoned that project and started a Third Person system. It works pretty well, until you jump. Nothing happens sometimes, but there are rare occasions where you'll jiggle around when you "jump." I investigated the problem and found that the controller won't say the character is grounded. Here's a little video that shows my problem. (On-Screen Keyboard shows that I'm sure I'm hitting the spacebar)
Here's my JavaScript:
//Public Variables
public var walkSpeed : float; //Set to 16
public var jumpPower : float; //Set to 10
public var rotSpeed : float; //Set to 5
public var playerCamera : GameObject; //Set to the Camera
public var failedCanvas : GameObject; //Set to a UI. Not relevant
public var normalCanvas : GameObject; //Set to a UI. Not relevant
public var upperTorso : GameObject; //Set to the upper part of the Character's Torso
//Private Variables
private var gravity : float = 400.0; //Effects how fast the player falls
private var moveDirection : Vector3 = Vector3.zero;
private var origWalkSpeed : float = 0;
function Start(){
//Cursor.visible = false;
origWalkSpeed = walkSpeed;
}
function FixedUpdate(){
var controller = GetComponent.<CharacterController>();
var animController = GetComponent.<Animator>();
moveDirection = transform.TransformDirection(Vector3(-Input.GetAxisRaw("Horizontal"), 0, -Input.GetAxisRaw("Vertical"))) * walkSpeed;
if(Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0){
animController.SetBool("Walking", true);
} else {
animController.SetBool("Walking", false);
}
if(Input.GetButton("Jump") && controller.isGrounded){
print("Jumping");
moveDirection.y = jumpPower;
animController.ResetTrigger("Jump");
}
if(Input.GetButton("Run") && (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0)){
animController.SetBool("Running", true);
walkSpeed = origWalkSpeed*1.5;
} else {
animController.SetBool("Running", false);
walkSpeed = origWalkSpeed;
}
if(!controller.isGrounded){moveDirection.y -= gravity * Time.deltaTime;}
}
I don't see why it should work any different than my FPS system. It worked fine (Still does in the FPS system) and my character has the same setup. When I added print(controller.isGrounded); all I got was a console of falses. Here's a picture of my character setup
Why isn't it grounded? I'm not falling through the floor... or floating on the floor.
Your answer
Follow this Question
Related Questions
How to move my rigid body in the direction my model is facing. 0 Answers
Gravity To CharacterController 0 Answers
Question on Unity5 CharacterController performance/efficiency 0 Answers
Making a 2D platformer, where am I going wrong? 0 Answers
CharacterController gets stuck between two or more box colliders 0 Answers