Question by
kissbertalan07 · Jul 28, 2020 at 12:31 PM ·
jumpjumpingnot workingcodepage1st person
Jump not working
Hello. I writed this code by following brackeys video but i don't know why the character don't jump. Please help me. (3D game) Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -19.62f;
public float jumpHeight = 3.88f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
// Update is called once per frame
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if(isGrounded && velocity.y < 0);
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
if(Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
My Player Doesn't Jump 0 Answers
Character jumping too fast 1 Answer
How can I modify this to allow jumping with space? 0 Answers
Jumping higher the more you hold space! 1 Answer
Moving and jumping 1 Answer