Search Unity

Jump error

Discussion in 'Scripting' started by sjameselvis, Sep 28, 2019.

  1. sjameselvis

    sjameselvis

    Joined:
    Aug 28, 2019
    Posts:
    30
    Hello, I have made an script witch makes the player jump, but when I hit play the player goes to the orbit.... I need some help =)))
    Code (CSharp):
    1. private void JumpInput ()
    2.     {
    3.         if (Input.GetKeyDown("space") && !isJumping);
    4.         {
    5.             isJumping = true;
    6.             StartCoroutine(JumpEvent());
    7.         }
    8.     }
    9.  
    10.     private IEnumerator JumpEvent()
    11.     {
    12.         charController.slopeLimit = 90.0f;
    13.         float timeInAir = 0.0f;
    14.  
    15.         do
    16.         {
    17.             float jumpForce = jumpCurve.Evaluate(timeInAir);
    18.             charController.Move(Vector3.up * jumpForce * jumpMultipler * Time.deltaTime);
    19.             timeInAir += Time.deltaTime;
    20.             yield return null;
    21.         } while (!charController.isGrounded && charController.collisionFlags != CollisionFlags.Above);
    22.  
    23.         isJumping = false;
    24.         charController.slopeLimit = 45.0f;
    25.     }
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,595
    A good start point is to become familiar with debugging techniques. A simple start can be made using something like
    Debug.Log("some Value = " + someValue.ToString());
    .

    Even better if you can install and use a debugger (Visual Studio for example can be downloaded for free).

    With this in mind, you may want to look at the
    jumpForce
    that is being calculated each frame. Is it generating the values you are expecting?
     
unityunity