I'm embarrassed to post this here, as there are already several instances of this question on the boards but sadly no proper answers. This is the Update method of my PlayerControl script:
void Update()
{
moveDirectionX = 0f;
moveDirectionY = 0f;
// Check Ground
grounded = Physics.Raycast(transform.position, -transform.up, deltaGround, 1 << LayerMask.NameToLayer("Environment"));
// Check Horizontal Movement
float h = Input.GetAxis("Horizontal");
moveDirectionX += h * moveForce;
// Check Jump
if (Input.GetKeyDown (KeyCode.Space) & grounded) {
jumping = true;
moveDirectionY += jumpForce;
}
// Add Gravity
if (!grounded)
moveDirectionY += gravityForce;
// Move the controller
moveDirection = new Vector3(moveDirectionX * Time.deltaTime, moveDirectionY * Time.deltaTime);
cc.Move(moveDirection * Time.deltaTime);
}
The part commented as `// Check Jump` shows how I'm currently handling the jump, basically by adding "JumpForce" to the vertical movement.
This is the method shown in quite a few posts on how to handle a jump with the Character Controller. But as far as I can tell, this is a horrible solution.
After reaching a certain height, the character falls pretty smoothly with the gravity. That is OK.
The problem is getting to that height. The character "teleports" (actually he's not teleporting he's just moving ridiculously fast) to the max height.
**How can you get a smooth jump with a CharacterController?**
I'm talking a jump that looks decent in like a Mario game.
↧