예제 #1
0
 void FixedUpdate()
 {
     ReceiveValues();
     input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
     UpdateSign();
     if (onGround)
     {
         velocity.y = 0;
     }
     if (control) //If player currently has control over character
     {
         if (onGround)
         {
             if (input.x != 0.0f) //If player input a direction
             {
                 if (sprinting)   //If player continuously moved in same direction for momentumTime(2.5 seconds), sprint
                 {
                     move.Sprint(ref velocity, input.x, onSlope);
                 }
                 else
                 {
                     velocity.x = input.x * moveSpeed;
                 }
                 if (onQuicksand)
                 {
                     velocity.x = velocity.x / 2.0f;
                 }
             }
             else //No input
             {
                 velocity.x = 0;
             }
             if (jumping) //If on quicksand, cut jump speed by 4, else jump normally
             {
                 velocity.y = onQuicksand ? jumpVelocity / 2.0f : jumpVelocity;
                 jumping    = false;
             }
         }
         else if (airborne)
         {
             if (input.x != 0.0f)                        //If player input a direction
             {
                 if (Mathf.Abs(velocity.x) >= moveSpeed) //Influence if airborne velocity x greater than movespeed
                 {
                     velocity.x += input.x * 0.04f;
                 }
                 else
                 {
                     velocity.x += input.x * 0.2f; //Influence if airborne velocity x less than movespeed
                 }
             }
             else //No input
             {
                 if (Mathf.Abs(velocity.x) > 1.0f) //Airborne movement influence
                 {
                     velocity.x = velocity.x / 1.01f;
                 }
             }
             if (Mathf.Abs(velocity.x) > 1.0f) //Airborne horizontal movement dampening
             {
                 velocity.x = velocity.x / 1.01f;
             }
             if (doubleJumping) //Second jump
             {
                 velocity.y = jumpVelocity;
             }
             if (velocity.y <= 0.0f) //Fast descending
             {
                 velocity.y -= Mathf.Pow(gravity, 2) * Time.deltaTime;
             }
             else //Dampen rising speed
             {
                 velocity.y  = velocity.y / 1.1f;
                 velocity.y -= gravity * Time.deltaTime;
             }
         }
         if (onWall)
         {
             if (sign == -wallSign)
             {
                 if (onGround || wallStickTimer > 0.0f)
                 {
                     velocity.x = -velocity.x;
                 }
             }
             if (wallSliding)
             {
                 if (velocity.y > wallSlideSpeed)
                 {
                     velocity.y = wallSlideSpeed;
                 }
             }
         }
     }
     else if (wallClimbing)
     {
         wallActions.WallClimbMove(ref velocity, wallSign);
     }
     else if (wallJumping)
     {
         wallActions.WallJumpMove(ref velocity, wallSign);
     }
     else if (dashing)
     {
         pDash.Dash(ref velocity, dashDir);
     }
     else if (pivoting)
     {
         move.Pivot(ref velocity, pivotSign, pivotTimer);
     }
     else if (diving && !diveHit)
     {
         pDive.Dive(ref velocity);
     }
     else if (diveHit && diveAttackTimer <= 0.0f)
     {
         pDive.Rebound(ref velocity, sign);
     }
     else if (attacking)
     {
         pAttack.Attack(ref velocity, sign);
     }
     else if (stunned)
     {
         pCol.Knockback(ref velocity, enemyColSign);
     }
     if (againstCeiling)
     {
         velocity.y = -3.0f;
     }
     if (onWall && wallStickTimer > 0.0f)
     {
         velocity.x = wallSign * 3.0f;
     }
     if (onSlope && input.x != 0.0f && velocity.y <= 0.0f)
     {
         move.DescendSlope(ref velocity);
     }
     if (!dashing && !doubleJumping)
     {
         LimitSpeed();
     }
     if (doubleJumping)
     {
         doubleJumping = false;
     }
     if (death)
     {
         velocity = Vector2.zero;
     }
     SendValues();
     animator.AnimatorSpeedX(Mathf.Abs(velocity.x));
     animator.AnimatorSpeedY(velocity.y);
     PlayerManager.instance.updateHealth(velocity.magnitude, inMist);
     transform.Translate(velocity * Time.deltaTime);
 }