Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Hollow knight style jumping

Discussion in 'Scripting' started by Henry_mullin, Jan 7, 2021.

  1. Henry_mullin

    Henry_mullin

    Joined:
    Jan 3, 2021
    Posts:
    13
    so i made a third person controller and wanted a jump mechanic kinda like hallow knights. it didn't work and said i had some compiler errors. i couldn't figure out why and saw no compiler errors. can someone fix my code or post their own hallow knight jumping for me to use?
    heres my code:
    Code (CSharp):
    1.  if (Input.GetButtonDown("Jump"))
    2.         {
    3.            JumpButtonDown = True;
    4.         }
    5.         if(JumpButtonDown == True)
    6.         {
    7.            if(Input.GetButtonDown("Jump"))
    8.            {
    9.               Velocity.y = Mathf.Sqrt(JumpHeight * -2f * Gravity);
    10.            }
    11.            else
    12.            {
    13.                Velocity.y = Mathf.Sqrt(JumpHeight * -1f * Gravity);
    14.                JumpButtonDown = False;
    15.            }
    16.         }
    id be really grateful if someone could help
     
    Last edited: Jan 7, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Let me offer you this riddle:

    It is
    true
    that you must pay attention to capitalization.

    It is
    false
    that capitalization does not matter. :)
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Also, check the radio buttons in the upper right corner of your console window. There are three... make sure they are all enabled.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Also
    Code (CSharp):
    1. if(JumpButtonDown = True)
    is definitely a bug. You want
    ==
    for checking equality. A single
    =
    is an assigment.
     
    Kurt-Dekker likes this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Also, line 5 probably should be two equals signs...
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Also... why are you checking jump... the checking jump?!
     
  7. Henry_mullin

    Henry_mullin

    Joined:
    Jan 3, 2021
    Posts:
    13
    checking jump automatically means the space bar
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Follow the logic:

    Line 1 checks the Jump Input, then sets a boolean.

    Later on, AFTER you check the boolean, you check the Jjump input again.

    ALSO: the test on line 5 will NEVER fail: you used one equal sign instead of 2 equal signs. See posts above.
     
  9. Henry_mullin

    Henry_mullin

    Joined:
    Jan 3, 2021
    Posts:
    13
    its not a boolean its a float. i wrote at the top where you assign the variables and stuff

    Code (CSharp):
    1. float JumpButtonDown = False;
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    This makes no sense to me so I will bow out now.
     
  11. Henry_mullin

    Henry_mullin

    Joined:
    Jan 3, 2021
    Posts:
    13
    im sorry. im brand new to coding and didnt know it was supposed to be a boolean. im only 13 and started about a month ago
     
  12. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,009
    You really saw no compilation error after this... ?
    Code (CSharp):
    1.    
    2. float JumpButtonDown = False;
    3.  
    OK you might be telling the truth, but it was there ?

    You cannot implicitly convert boolean to float in c#.
     
    PraetorBlue likes this.
  13. Henry_mullin

    Henry_mullin

    Joined:
    Jan 3, 2021
    Posts:
    13
    i didnt check. im new to coding. but i fixed the problem and the code was waaay simpler than ithought.