why is jumping not working please help

Jumping part is in Blue, Thanks!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movement : MonoBehaviour
{
public Transform groundcheck;
public CharacterController controuler;

public float jumphigh;
public float movingspeed;
public float currentspeed = 0f;
public float timetocometostop = 50f;
public float gravity = 10f;
public float checkradius = 0.5f;
public LayerMask la;

float currentgrafyty;
bool ismoving = false;
Vector3 dir;
float currentdirectionx;
float currentdirectiony;
Vector3 velocety;
public bool isgrounded = false;

// Update is called once per frame
void Update()
{

isgrounded = Physics.CheckSphere(groundcheck.position, checkradius, la);

//basic movement
if(Input.GetKey(“w”) || Input.GetKey(“s”) || Input.GetKey(“a”) || Input.GetKey(“d”) && currentspeed != movingspeed)
{
controuler.Move(dir * currentspeed * Time.deltaTime);

float x = Input.GetAxisRaw(“Horizontal”);
float y = Input.GetAxisRaw(“Vertical”);

currentdirectionx = x;
currentdirectiony = y;

dir = transform.right * x + transform.forward * y;
ismoving = true;
if(ismoving == true)
{
currentspeed += timetocometostop * Time.deltaTime;
}

}
else if (currentspeed >= 0f)
{
dir = transform.right * currentdirectionx + transform.forward * currentdirectiony;
controuler.Move(dir * currentspeed * Time.deltaTime);
ismoving = false;
if (ismoving == false)
{
currentspeed -= timetocometostop* Time.deltaTime;
}

}

if(currentspeed <= 0f)
{
currentspeed = 0f;
}

if(currentspeed >= movingspeed)
{
currentspeed = movingspeed;
}
//basic movement end

//Jumping
if (Input.GetButton(“Jump”) && isgrounded == true)
{
Debug.Log(“Jump”);
currentgrafyty += jumphigh;
}
//Jumping end

//velocety
if(isgrounded == false)
{
currentgrafyty -= gravity * Time.deltaTime;
}
else
{
currentgrafyty = 0f;
}

velocety = transform.up * currentgrafyty;

controuler.Move(velocety * Time.deltaTime);

//velocety end
}
}

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand errors in general:

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run?
  • what are the values of the variables involved? Are they initialized?

Knowing this information will help you reason about the behavior you are seeing.

Also, here’s a cheap and cheerful CC-based solution, full code and package:

I wrote about this before: the Unity example code in the API no longer jumps reliably. I have reported it. Here is a work-around:

1 Like