Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        player        = GameObject.Find("Player");
        gravityScript = player.GetComponent <gravityHandler>();
        //Set switch in the right direction for initial gravity
        currOrientation = gravityScript.GetGravityOrientation();
        SetIndexReference(currOrientation);
        transform.rotation = SetSwitchRotation(currOrientation);

        //Array of all orientations
        orientations = new gravityHandler.GravityOrientation[] {
            gravityHandler.GravityOrientation.Up,
            gravityHandler.GravityOrientation.Right,
            gravityHandler.GravityOrientation.Down,
            gravityHandler.GravityOrientation.Left
        };
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1") && player.GetComponent <playerController>().move)
        {
            //Shoot raycast to detect if the player shot at the gravity switch
            int     platform  = LayerMask.GetMask("Platform", "PortalPlatform"); //the switch is on the platform layer
            Vector2 playerPos = player.transform.position;
            Vector2 target    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 direction = target - playerPos;

            RaycastHit2D hit = Physics2D.Raycast(playerPos, direction, Mathf.Infinity, platform);

            if (hit && (hit.collider.name == "gravityBox" || hit.collider.name == "gravityBox - Ilum"))
            {
                currOrientation = gravityScript.GetGravityOrientation();
                UpdateOrientation();
            }
        }
    }
Ejemplo n.º 3
0
 void SetIndexReference(gravityHandler.GravityOrientation Or)
 {
     if (Or == gravityHandler.GravityOrientation.Up)
     {
         orIndex = 0;
     }
     else if (Or == gravityHandler.GravityOrientation.Right)
     {
         orIndex = 1;
     }
     else if (Or == gravityHandler.GravityOrientation.Down)
     {
         orIndex = 2;
     }
     else if (Or == gravityHandler.GravityOrientation.Left)
     {
         orIndex = 3;
     }
 }
Ejemplo n.º 4
0
    public Vector2 Move(Vector2 moveAmount, GameObject entityGO)
    {
        float   deltaX         = moveAmount.x;
        float   deltaY         = moveAmount.y;
        Vector2 entityPosition = entityGO.transform.position;
        var     gravity        = GetComponent <gravityHandler>();

        gravityHandler.GravityOrientation gravityOr = gravity.GetGravityOrientation();

        if (gravityOr == gravityHandler.GravityOrientation.Up || gravityOr == gravityHandler.GravityOrientation.Down)
        {
            verticalGravity = true;
        }
        else
        {
            verticalGravity = false;
        }

        touchingBox = false;
        inDoor      = false;

        //Resolve any possible collisions below and above the entity
        if (deltaY != 0 || verticalGravity)
        {
            deltaY = YAxisCollisions(deltaY, Mathf.Sign(deltaX), entityPosition);
        }
        //Resolve any possible collisions left and right of the entity
        //Check if our deltaX value is 0 to avoid unnecessary collision checks
        if (deltaX != 0 || !verticalGravity)
        {
            deltaX = XAxisCollisions(deltaX, entityPosition);
        }
        //If moving sideways in air, resolve any possible diagonal collisions
        if (deltaX != 0 && deltaY != 0 && !SideCollision && !onGround)
        {
            DiagonalCollisions(ref deltaX, ref deltaY, entityPosition);
        }
        Vector2 finalTransform = new Vector2(deltaX, deltaY);

        return(finalTransform);
    }
Ejemplo n.º 5
0
    Quaternion SetSwitchRotation(gravityHandler.GravityOrientation Or)
    {
        Quaternion rot = transform.rotation;

        if (Or == gravityHandler.GravityOrientation.Up)
        {
            rot = Quaternion.Euler(0, 0, 0);
        }
        else if (Or == gravityHandler.GravityOrientation.Right)
        {
            rot = Quaternion.Euler(0, 0, 270);
        }
        else if (Or == gravityHandler.GravityOrientation.Down)
        {
            rot = Quaternion.Euler(0, 0, 180);
        }
        else if (Or == gravityHandler.GravityOrientation.Left)
        {
            rot = Quaternion.Euler(0, 0, 90);
        }
        return(rot);
    }