I have two sets of platforms: one set is moving downward and the others are moving upward. The character will not jump on the downward platforms, but will on the upward ones. Im using CharacterController.isGrounded method of collision to be able to jump. My guess is that its not registering that connection when the platform is essentially falling, but the character is clearly standing on it because it will animate the walk while moving back and forth as if it is registering the grounding. Any ideas?
Thanks!
void Update()
{
//Assign static variable
stopControls1 = stopControls;
//Move Player
PlayerRun();
}
//Player control
void PlayerRun()
{
if(!stopControls)
{
//Check if is on the ground
if(charController.isGrounded)
{
//If grounded, set to false
walkJumpOn = false;
runJumpOn = false;
crouchJumpOn = false;
if(!isCrouched)
{
if (!freeFall)
{
//Set key movement
moveDirection = new Vector3 (Input.GetAxis ("LeftAndRight"), 0);
charController.Move (moveDirection * Time.deltaTime);
}
//Rotate
if (moveDirection != Vector2.zero)
{
Quaternion newRotation = Quaternion.LookRotation(moveDirection);
thisTransform.transform.rotation = Quaternion.Slerp(thisTransform.transform.rotation,
newRotation, Time.deltaTime * 20);
}
//If is moving
if(moveDirection.magnitude > 0.05f)
{
//walk
if(!Input.GetKey(KeyCode.M))
{
maxSpeed = 6;
moveDirection *= walkSpeed;
thisTransform.GetComponent<Animation>().CrossFade("Run");
}
//run
else
{
maxSpeed = 10;
moveDirection *= runSpeed;
thisTransform.GetComponent<Animation>().CrossFade("Sprint");
}
//idle
else
{
thisTransform.GetComponent<Animation>().CrossFade("Idle");
}
}
//JUMP COMMANDS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Idle jump height
if(Input.GetButtonDown("Jump") && (!Input.GetKey(KeyCode.M) || Input.GetKey (KeyCode.M)
&& moveDirection.x == 0) && Input.GetAxis("Crouch") >= 0)
{
AudioControl.JumpSound();
CreateDust();
moveDirection.y = walkJump;
moveDirection.x = walkSpeed;
walkJumpOn = true;
}
//Sprinting jump height
if(Input.GetButtonDown("Jump") && Input.GetKey(KeyCode.M) && moveDirection.x != 0)
{
AudioControl.JumpSound();
CreateDust();
moveDirection.y = runJump;
runJumpOn = true;
}
//Walking jump height
if(Input.GetButtonDown("Jump") && moveDirection.x == 0 && Input.GetKey(KeyCode.S))
{
AudioControl.JumpSound();
CreateDust();
moveDirection.y = walkJump;
crouchJumpOn = true;
}
}
//If not on the ground...
if(!charController.isGrounded)
{
//Assign inputs
moveDirection.x = Input.GetAxis("LeftAndRight");
//If jump key is let go, fall to the ground
if(Input.GetButtonUp("Jump"))
{
moveDirection.x = 0;
moveDirection.y = moveDirection.y - fallSpeed;
}
//Create gravity
moveDirection.y -= gravity * Time.deltaTime;
//Check for jump input
charController.Move(moveDirection * Time.deltaTime);
}
}