Jumping (isgrounded) dose not work porperly

Updated on July 11, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on July 11, 2017

Hey guys im currently working on a game. And im currently stuck with some jumping mechanics. my map looks like this (https://gyazo.com/8bc0da1e96fec42e9b0ab183b33cbdb6) (just to get an idea of how it is) and then problem is that the charactercontroller,s isgrounded isn’t reliable. My current code is: 

 

 
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PlayerJump: MonoBehaviour
{
 private CharacterController controller;
 
private float verticalVelocity;
 private float gravity = 14.0f;
 private float jumpForce = 10.0f;
 
private void Start()
 {
 controller = GetComponent();
 }
 
private void Update()
 {
 if (controller.isGrounded)
 {
 verticalVelocity = -gravity * Time.deltaTime;
 if (Input.GetKeyDown(KeyCode.Space))
 {
 verticalVelocity = jumpForce;
 }
 }
 else
 {
 verticalVelocity -= gravity * Time.deltaTime;
 }
 
Vector3 moveVector = new Vector3(0, verticalVelocity, 0);
 controller.Move(moveVector * Time.deltaTime);
 }
}
 

i dont know what to do would love some help 🙂

  • Liked by
Reply