Beispiel #1
0
    //Function to hold the raycasts at its place in relation to the object scale
    public void ScaleToOffsetPoints()
    {
        bool rayReplace = true;

        if (rayReplace == true)
        {
            float oldHalfRayLength = halfRayLength;

            //this fixes a bug where the left and right rays will switch because the x scale is minus. this way it tackles it
            if (transform.localScale.x >= 0)
            {
                halfRayWidth = width / 2 * transform.localScale.x;
            }
            else if (transform.localScale.x < 0)
            {
                halfRayWidth = width / 2 * -transform.localScale.x;
            }

            halfRayLength = length / 2 * transform.localScale.y;
            moveDown      = new RaycastMoveDirection(new Vector2(-halfRayWidth, -halfRayLength), new Vector2(halfRayWidth, -halfRayLength), Vector2.down,
                                                     platformMask, Vector2.right * parallelInsetLen, Vector2.up * perpendicularInsetLen);
            moveLeft = new RaycastMoveDirection(new Vector2(-halfRayWidth, -halfRayLength), new Vector2(-halfRayWidth, halfRayLength), Vector2.left,
                                                platformMask, Vector2.up * parallelInsetLen, Vector2.right * perpendicularInsetLen);
            moveUp = new RaycastMoveDirection(new Vector2(-halfRayWidth, halfRayLength), new Vector2(halfRayWidth, halfRayLength), Vector2.up,
                                              platformMask, Vector2.right * parallelInsetLen, Vector2.down * perpendicularInsetLen);
            moveRight = new RaycastMoveDirection(new Vector2(halfRayWidth, -halfRayLength), new Vector2(halfRayWidth, halfRayLength), Vector2.right,
                                                 platformMask, Vector2.up * parallelInsetLen, Vector2.left * perpendicularInsetLen);

            groundDown = new RaycastCheckTouch(new Vector2(-halfRayWidth, -halfRayLength), new Vector2(halfRayWidth, -halfRayLength), Vector2.down,
                                               platformMask, Vector2.right * parallelInsetLen, Vector2.up * perpendicularInsetLen, groundTestLen);
            transform.position = new Vector3(transform.position.x, transform.position.y + oldHalfRayLength / 2, transform.position.z);
            rayReplace         = false;
        }
    }
Beispiel #2
0
 void Start()
 {
     sr       = GetComponent <SpriteRenderer>();
     moveDown = new RaycastMoveDirection(new Vector2(-0.5f, 0f), new Vector2(0.5f, 0f), Vector2.down, platformMask,
                                         Vector2.right * parallelInsetLen, Vector2.up * perpendicualrInsetLen);
     moveLeft = new RaycastMoveDirection(new Vector2(-0.5f, 0f), new Vector2(-0.5f, 1.7f), Vector2.left, platformMask,
                                         Vector2.up * parallelInsetLen, Vector2.right * perpendicualrInsetLen);
     moveUp = new RaycastMoveDirection(new Vector2(-0.5f, 1.7f), new Vector2(0.5f, 1.7f), Vector2.up, platformMask,
                                       Vector2.right * parallelInsetLen, Vector2.down * perpendicualrInsetLen);
     moveRight = new RaycastMoveDirection(new Vector2(0.5f, 0f), new Vector2(0.5f, 1.7f), Vector2.right, platformMask,
                                          Vector2.up * parallelInsetLen, Vector2.left * perpendicualrInsetLen);
     groundDown = new RaycastCheckTouch(new Vector2(-0.5f, 0f), new Vector2(0.5f, 0f), Vector2.down, platformMask,
                                        Vector2.right * parallelInsetLen, Vector2.up * perpendicualrInsetLen, groundTestLen);
 }
Beispiel #3
0
    // Start is called before the first frame update
    protected void Awake()
    {
        moveDown = new RaycastMoveDirection(new Vector2(-0.5f, 0f), new Vector2(0.5f, 0f), Vector2.down, platformMask,
                                            Vector2.right * parallelInsetLen, Vector2.up * perpendicualrInsetLen);
        moveLeft = new RaycastMoveDirection(new Vector2(-0.5f, 0f), new Vector2(-0.5f, 1.7f), Vector2.left, platformMask,
                                            Vector2.up * parallelInsetLen, Vector2.right * perpendicualrInsetLen);
        moveUp = new RaycastMoveDirection(new Vector2(-0.5f, 1.7f), new Vector2(0.5f, 1.7f), Vector2.up, platformMask,
                                          Vector2.right * parallelInsetLen, Vector2.down * perpendicualrInsetLen);
        moveRight = new RaycastMoveDirection(new Vector2(0.5f, 0f), new Vector2(0.5f, 1.7f), Vector2.right, platformMask,
                                             Vector2.up * parallelInsetLen, Vector2.left * perpendicualrInsetLen);

        groundDown = new RaycastCheckTouch(new Vector2(-0.5f, 0f), new Vector2(0.5f, 0f), Vector2.down, platformMask,
                                           Vector2.right * parallelInsetLen, Vector2.up * perpendicualrInsetLen, groundTestLen);
    }
    void Start()
    {
        spriteRenderer = GetComponent <SpriteRenderer>();
        playerAnim     = GetComponent <PlayerAnim>();
        boxCollider    = GetComponent <BoxCollider2D>();
        audioManager   = FindObjectOfType <AudioManager>();

        moveDown = new RaycastMoveDirection(new Vector2(-0.5f, -0.75f), new Vector2(0.5f, -0.75f), Vector2.down, platformMask,
                                            Vector2.right * parallelInsetLen, Vector2.up * perpendicularInsetLen);
        moveLeft = new RaycastMoveDirection(new Vector2(-0.5f, -0.75f), new Vector2(-0.5f, 0.75f), Vector2.left, platformMask,
                                            Vector2.up * parallelInsetLen, Vector2.right * perpendicularInsetLen);
        moveUp = new RaycastMoveDirection(new Vector2(-0.5f, 0.75f), new Vector2(0.5f, 0.75f), Vector2.up, platformMask,
                                          Vector2.right * parallelInsetLen, Vector2.down * perpendicularInsetLen);
        moveRight = new RaycastMoveDirection(new Vector2(0.5f, -0.75f), new Vector2(0.5f, 0.75f), Vector2.right, platformMask,
                                             Vector2.up * parallelInsetLen, Vector2.left * perpendicularInsetLen);

        groundDown = new RaycastCheckTouch(new Vector2(-0.5f, -0.75f), new Vector2(0.5f, -0.75f), Vector2.down, platformMask,
                                           Vector2.right * parallelInsetLen, Vector2.up * perpendicularInsetLen, groundTestLen);
    }
    void Start()
    {
        facingRight = true;
        // atira o raycast
        moveDown = new RaycastMoveDirection(new Vector2(-0.5f, -0.70f), new Vector2(0.5f, -0.70f), Vector2.down, platformMask,
                                            Vector2.right * parallelInsetLen, Vector2.up * perpendicularInsetLen);
        moveLeft = new RaycastMoveDirection(new Vector2(-0.5f, -0.70f), new Vector2(-0.5f, 0.70f), Vector2.left, platformMask,
                                            Vector2.up * parallelInsetLen, Vector2.right * perpendicularInsetLen);
        moveRight = new RaycastMoveDirection(new Vector2(0.5f, -0.70f), new Vector2(0.5f, 0.70f), Vector2.right, platformMask,
                                             Vector2.up * parallelInsetLen, Vector2.left * perpendicularInsetLen);
        moveUp = new RaycastMoveDirection(new Vector2(-0.5f, 0.70f), new Vector2(0.5f, 0.70f), Vector2.up, platformMask,
                                          Vector2.right * parallelInsetLen, Vector2.down * perpendicularInsetLen);


        groundDown = new RaycastCheckTouch(new Vector2(-0.5f, -0.70f), new Vector2(0.5f, -0.70f), Vector2.down, platformMask,
                                           Vector2.right * parallelInsetLen, Vector2.up * perpendicularInsetLen, groundTestLen);

        animator       = GetComponent <Animator>();
        spriteRenderer = GetComponent <SpriteRenderer>();
        extraJumps     = extraJumpsValue;
        weapon         = GetComponent <Weapon>();
    }