I have this really strange problem where my code that I use for jumping reacts differently depending on if I’m playing in the Editor, Editor maximize on play or web player!
In the editor the jumping works great
In maximize on play mode, it suddenly jumps really low and fast
in web player it jumps really high and slow
I’m not sure what I’m doing wrong? Can anyone help me out?
My update function
function Update () {
if(userInput){
verticalInput = Input.GetAxisRaw("Vertical");
horizontalInput = Input.GetAxis("Horizontal");
}
UpdateMovement();
collisionFlag = characterController.Move(movement.direction * movement.runSpeed * Time.deltaTime);
if(collisionFlag == CollisionFlags.Above){
print("hit ceiling!");
movement.reachedApex = true;
movement.verticalSpeed -= 0.1;
}
}
Here is the jump code
function UpdateMovement(){
movement.direction = Vector3(horizontalInput, 0, 0);
if(characterController.isGrounded){
//if character just landed from a jump
if(movement.isJumping){
movement.isJumping = false;
movement.reachedApex = false;
}
if(verticalInput > 0){
movement.verticalSpeed = movement.minJumpHeight;
movement.direction.y += movement.verticalSpeed;
movement.isJumping = true;
}
else{
//stabilizes the characterController.isGrounded
movement.direction.y = -0.1;
}
}
else{
if(movement.isJumping){
if(verticalInput > 0 !movement.reachedApex)
movement.verticalSpeed += movement.jumpSpeed;
if(movement.verticalSpeed >= movement.maxJumpHeight)
movement.reachedApex = true;
if(movement.verticalSpeed > movement.gravity)
movement.verticalSpeed -= movement.jumpDrag;
movement.direction.y += movement.verticalSpeed;
}
else
//while falling, we don't want it to drop as fast so reduce the gravity
movement.direction.y += movement.gravity*0.6;
}
}