Search Unity

Jumping is to high sometimes (inconsistent)

Discussion in 'Navigation' started by ZlyzeOfficial, Mar 15, 2018.

  1. ZlyzeOfficial

    ZlyzeOfficial

    Joined:
    Mar 13, 2018
    Posts:
    7
    Hey, Im currently having the problem that my Sphere jumps inconsistent sometimes. Sometimes it jumps on the height i set to it and some and jumping way to high. Any ideas to fix it.


    using UnityEngine;
    using System.Collections;
    public class PlayerController : MonoBehaviour
    {
    public float speed;
    private Rigidbody rb;
    public LayerMask groundLayers;
    public float jumpForce = 7;
    public SphereCollider col;
    void Start()
    {
    rb = GetComponent<Rigidbody>();
    col = GetComponent<SphereCollider>();
    }
    void FixedUpdate()
    {
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");
    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    rb.AddForce(movement * speed);
    if (IsGrounded() && Input.GetKeyDown(KeyCode.Space))
    {
    rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
    }
    }
    private bool IsGrounded()
    {
    return Physics.CheckCapsule(col.bounds.center, new Vector3(col.bounds.center.x,
    col.bounds.min.y, col.bounds.center.z), col.radius * .5f, groundLayers);
    }
    }