Question by
nati99 · Jan 05, 2021 at 07:15 PM ·
character controllercharacter movement
Character jump
I am fairly new to Unity, I am trying to write a code for the character to jump, but when the character jumps it falls back down very slowly. How can I change this? Am I missing something? For reference, my gravity is set to -9.81.
void Update () {
InputMagnitude();
isGrounded = controller.isGrounded;
if (isGrounded)
{
verticalVel -= 0;
}
moveVector = new Vector3(0, verticalVel * .2f * Time.deltaTime, 0);
controller.Move(moveVector);
//jump
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2 * gravity);
}
//gravity
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
Comment
Your answer
Follow this Question
Related Questions
Error CS0103 0 Answers
I want to make an on click movement script with a grid type map need references to look at 0 Answers
infamous first light run code help 1 Answer
Trying to figure out WallRiding, with Vector3.Cross 0 Answers
Character controller for fixed perspective camera (moving relative to arbitrary point on screen) 0 Answers