Exemple #1
0
 public void changeDirection(characterDirection _direction)
 {
     direction = _direction;
 }
    // Detect if the player is sliding against a wall. We also update the character state accordingly
    bool detectWallSlide()
    {
        Debug.DrawRay (new Vector2 (_transform.position.x + 0.32f, _transform.position.y - 0.26f), Vector2.right, Color.green);
        Debug.DrawRay (new Vector2(_transform.position.x+0.32f,_transform.position.y+0.26f), Vector2.right, Color.green);
        Debug.DrawRay (new Vector2(_transform.position.x-0.32f,_transform.position.y+0.26f), -Vector2.right, Color.green);
        Debug.DrawRay (new Vector2(_transform.position.x-0.32f,_transform.position.y-0.26f), -Vector2.right, Color.green);

        // Split it in 2. Need to know if we're against left or right wall.
        if (Physics2D.Raycast (new Vector2 (_transform.position.x + 0.32f, _transform.position.y - 0.26f), Vector2.right, .03f, groundMask)
                        || Physics2D.Raycast (new Vector2 (_transform.position.x + 0.32f, _transform.position.y + 0.26f), Vector2.right, .03f, groundMask)) {
            currentCharacterState = characterState.SlideWall;
            currentCharacterDirection = characterDirection.Left;
            return true;
        } else if(Physics2D.Raycast (new Vector2 (_transform.position.x - 0.32f, _transform.position.y + 0.26f), -Vector2.right, .03f, groundMask)
            || Physics2D.Raycast (new Vector2 (_transform.position.x - 0.32f, _transform.position.y - 0.26f), -Vector2.right, .03f, groundMask)) {
            currentCharacterState = characterState.SlideWall;
            currentCharacterDirection = characterDirection.Right;
            return true;
        } else {
            return false;
        }
    }