Search Unity

Run/Walk Fellow Eteeski Students...

Discussion in 'Scripting' started by NightoutCoder, Jul 9, 2012.

  1. NightoutCoder

    NightoutCoder

    Joined:
    Jul 9, 2012
    Posts:
    6
    Hey there Friends I have a Small problem which is bugging me About running on Holding The Shift Key I added this in the update Function
    Code (csharp):
    1. if(Input.GetButton("Run"))
    2.     {
    3.       maxWalkSpeed=Mathf.SmoothDamp(maxWalkSpeed,maxRunSpeed,runVel,walkToRunAcc);
    4.       }
    5.         if(!Input.GetButton("Run"))
    6.     {
    7.       maxWalkSpeed=Mathf.SmoothDamp(maxWalkSpeed,maxWalkSpeed,runVel,walkToRunAcc);
    8.       }
    but its not working
    It speeds up and Runs on holding left shift , but never Goes back to walk mode..
    :-|

    maxRunSpeed>>maxWalkSpeed;walkToRunAcc =0.3
     
  2. jbufo

    jbufo

    Joined:
    Aug 16, 2010
    Posts:
    52
    Change the second if statement to else.

    I think that should work. I'm not sure ! works the way you want with Input.

    else will make it basically say 'otherwise, always make sure this is the case'
     
  3. jbufo

    jbufo

    Joined:
    Aug 16, 2010
    Posts:
    52
    It's not letting me edit my post so I'm jsut replying again.

    What I meant, if you're not familiar with it, was just plain old 'else' not to change the word if to the word else.

    Code (csharp):
    1. if (inputstuff blah (blah))
    2. {
    3. do this
    4. }
    5. else
    6. {
    7. make this the walk speed
    8. }
     
  4. NightoutCoder

    NightoutCoder

    Joined:
    Jul 9, 2012
    Posts:
    6
    "!" works dude ... i used the same techneaque which is used to Aim the gun...
     
  5. JoeCunningham

    JoeCunningham

    Joined:
    Jul 16, 2012
    Posts:
    2
    There is nothing wrong with using the exclamation mark (!).
    I think that I know the problem:

    The second if function is embedded. Just use an else statement or another if statement (non embedded)
     
  6. outsky

    outsky

    Joined:
    May 21, 2012
    Posts:
    41
    You modified the maxWalkSpeed without saving the original value.
    So how could you tell the game what the original walk speed is?

    First, save the original walk speed to a variable fOrgWalkSpeed, then do this:
    if(!Input.GetButton("Run"))

    {

    maxWalkSpeed=Mathf.SmoothDamp(maxWalkSpeed,fOrgWalkSpeed,runVel,walkToRunAcc);

    }
     
  7. NightoutCoder

    NightoutCoder

    Joined:
    Jul 9, 2012
    Posts:
    6
    HEY dude Your right I have to save original Velocity thanx ^.^
    Smoochieeessssssss