Search Unity

Advice on mountain climbing input

Discussion in 'Scripting' started by jimma, Sep 6, 2013.

  1. jimma

    jimma

    Joined:
    Apr 3, 2013
    Posts:
    28
    Hey guys,

    So I am trying to make my first person character climb the mountain. I have made the physics just about right. Now I want a good input system to make my character climb.

    This is what I am trying to achieve.

    User clicks mouse 0 which plays the right hand animation going up and latching the wall. Now I want the user to click mouse 1 which would play the left hand anim for latching the waill. After that the user moves upward with some velocity. The process repeats everytime when the user gives that input.

    Here is my input code.

    Code (csharp):
    1.  
    2.   if(Input.GetMouseButtonDown(0))
    3.                 {
    4.                 upMovement = true;
    5.                 //curTime = Time.time;
    6.                 playRightHandUpAnim = 1;
    7.                 //print("FIRST");
    8.                 yield WaitForSeconds(0.1f);
    9.                 playRightHandUpAnim = 0;
    10.                 print("NOW");
    11.                 yield WaitForSeconds(0.1f);
    12.                    if(Input.GetMouseButtonDown(1))
    13.                    {
    14.                         playLeftHandUpAnim = 1;
    15.                         //print("SECOND");
    16.                         yield WaitForSeconds(0.2f);
    17.                         playLeftHandUpAnim = 0;
    18.                         playLeftHandDownAnim = 1;
    19.                         playRightHandDownAnim = 1;
    20.                         yield WaitForSeconds(0.2f);
    21.                         playLeftHandDownAnim = 0;
    22.                         playRightHandDownAnim = 0;
    23.                        
    24.                         //print("CLIMB");
    25.                         verticalMove = climbDirection.normalized;
    26.                         verticalMove *= climbSpeed;
    27.                         lateralMove = Vector3.zero;
    28.                     }
    29.                 }
    30.                 else{
    31.                 upMovement = false;
    32.                 }
    33.  
    I have used the yield to have a minor pause for the animations to play correctly. I know I am missing out on something.Hope someone can help !

    Thanks!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    Last edited: Sep 6, 2013