Ejemplo n.º 1
0
        /* public void RotateClimbingCharacter(Vector3 currentVelocity)
         * {
         *   transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x) * Mathf.Sign(currentVelocity.x), transform.localScale.y, transform.localScale.z);
         * }*/
        public Vector3 PrepareMove(ref Vector3 velocity, Vector2 rawInput, float currJumpVelocity,
                                   float currDoubleJumpFactor, float currClimbMoveSpeed, float currGravity, float lastFrameTime)
        {
            Vector3 timeScaledVelocity;

            //Check if the player is climbing or standing on ground or colliding with ceiling.
            //If yes - set their Y velocity to 0
            velocity.y = ChkVerticalCollisions(velocity.y);

            _currClimbMoveSpeed   = currClimbMoveSpeed;
            _currDoubleJumpFactor = currDoubleJumpFactor;
            _currJumpVelocity     = currJumpVelocity;

            currGravity *= lastFrameTime;

            ChkInputs(ref velocity, rawInput, currGravity);
            timeScaledVelocity = new Vector3(velocity.x, velocity.y, velocity.z);
            //Finished checking input. Multiply the velocity and gravity by last frame time.
            timeScaledVelocity *= lastFrameTime;

            SetClimbingYProjectionLength(currGravity);

            if (Mathf.Abs(timeScaledVelocity.x) < InputPadding)
            {
                timeScaledVelocity.x = 0;
            }
            collisions.Reset();

            bool isClimbingUpKeyPressed = RuyoInputReceiver.GetInstance().GetKey(RuyoInputReceiver.ClimbKey);

            ClimbingUpOrDown();
            movement.SetIsClimbing(isClimbingUpKeyPressed);
            UpdateRayCastOrigins();


            collisions.velocityOld = timeScaledVelocity;

            if (timeScaledVelocity.y < 0 && !IsClimbingWall())
            {
                DescendSlope(ref timeScaledVelocity);
            }

            if (IsFloatZero(timeScaledVelocity.x) == false)
            {
                HorizontalCollisions(ref timeScaledVelocity);
            }

            if (IsClimbingWall() && !(collisions.below || collisions.above))
            {
                ChkWallCollisions(ref timeScaledVelocity);//TODO repair the x velocity when shift pressed bug in here
            }

            if (IsFloatZero(timeScaledVelocity.y) == false)
            {
                VerticalCollisions(ref timeScaledVelocity);
            }

            movement.ResetDoubleJump(collisions);

            //transform.Translate(velocity);

            NotifyObservers();

            return(timeScaledVelocity);
        }