#jump not work properly

1 messages · Page 1 of 1 (latest)

light obsidian
#

sometimes when i jump it doesnt work properly, i need to click multiple times for it to work, im following the brakeys 1st person player movement tutorial
help please.
my code: ```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

#region Var

//Movement Var
public CharacterController CONTROLLER;
public float playerSPEED = 25f;

//Gravity Var
public float GRAVITY =  -9.81f;
Vector3 velocity;

//GroundCheck Var
public Transform groundCHECK;
public float groundDISTANCE;
public LayerMask groundMASK;
bool isGrounded = false;

//Jump Var
public float jumpHIGHT = 3F;
#endregion

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

    //Input
    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");

    //IsGrounded Code
    isGrounded = Physics.CheckSphere(groundCHECK.position, groundDISTANCE, groundMASK);

    velocity.y += GRAVITY * Time.deltaTime;
    if(isGrounded) {
        velocity.y = 0;
    }

    //Calcutating Direction To Move
    Vector3 move = transform.right * x + transform.forward * z;

    //Moving
    CONTROLLER.Move(move * playerSPEED * Time.deltaTime);

    //Jump
    if (Input.GetButtonDown("Jump"))
    {
        velocity.y = Mathf.Sqrt(jumpHIGHT * -2 * GRAVITY);
    }

    //Gravity
    

    CONTROLLER.Move(velocity * Time.deltaTime);
}

}```

#

video example:

#

help please

quick ridge
#

no clue what's the issue, but this line looks very wrong to me:
"Vector3 move = transform.right * x + transform.forward * z;"

light obsidian
#

Me too but it was toldin the tutorial: https://youtu.be/_QajrabyTJc
And it gets the job done

quick ridge
#

can you Debug.Log the value of isgrounded and check wether it's actually true?

light obsidian
#

It is true i used the debug mode inspector that was my first instinct

quick ridge
#

groundcheck, groundDistance and groundmask are set properly?

light obsidian
#

They are

#

no clue where the velocity actually gets applied, but if the velocity are absolute values, you try to jump for one frame, then set the upward velocity back to 0 on the next frame with

            velocity.y = 0;
        }```
#

You said this

#

I think it might just be it

quick ridge
#

yeh, but I can't make sense of it just yet

light obsidian
#

I'll make a work around for this if it is the problem tomm as it should s getting late for me and i gtg