public virtual void Update()
    {
        isTouchingGround      = belowInput.isColliding;
        isTouchingCeiling     = aboveInput.isColliding;
        isTouchingWallInFront = frontInput.isColliding;

        //Attach to moving platform below
        if (!rb.isKinematic)
        {
            if (belowInput.collidingPlatformControllers.Count != 0)
            {
                if (!belowInput.collidingPlatformControllers.Contains(platformBelowController))
                {
                    platformBelowController = belowInput.collidingPlatformControllers[belowInput.collidingPlatformControllers.Count - 1];

                    Debug.Log(platformBelowController.gameObject.name);
                }
            }
            else
            {
                platformBelowController = null;
            }

            if (belowInput.isColliding && platformBelowController != null)
            {
                platformBelowController.AddPassengerRB(rb);
            }
        }

        //Apply gravity;
        if (velocity.y <= 0)
        {
            velocity.y += -gravity * 3 * Time.deltaTime;
        }
        else
        {
            velocity.y += -gravity * Time.deltaTime;
        }

        //Stop moving if hitting ceiling or ground
        if (velocity.y > 0 && aboveInput.isColliding)
        {
            velocity.y = 0;
        }

        if (velocity.y < 0 && belowInput.isColliding)
        {
            velocity.y = 0;
        }

        //Draw line for debugging
        Debug.DrawLine(lastPosition, transform.position, Color.white, 1f);
        lastPosition = transform.position;
    }
Esempio n. 2
0
    public override void Update()
    {
        if (Time.timeScale != 0)
        {
            base.Update();

            if (belowInput.isColliding && velocity.y == 0)
            {
                rb.isKinematic = true;
            }
        }

        if (belowInput.collidingObjects.Count != 0 && !pairedToPlatform)
        {
            platformConnectedTo = belowInput.collidingObjects[0];
            sr.sortingLayerID   = platformConnectedTo.GetComponent <TilemapRenderer>().sortingLayerID;
            sr.sortingOrder     = platformConnectedTo.GetComponent <TilemapRenderer>().sortingOrder;
            pairedToPlatform    = true;

            platformControllerBelow = platformConnectedTo.GetComponent <PlatformController>();
        }
        else if (belowInput.collidingObjects.Count == 0 && pairedToPlatform)
        {
            platformConnectedTo     = null;
            platformControllerBelow = null;
            pairedToPlatform        = false;
        }

        if (platformControllerBelow != null && passengerrbs.Count > 0)
        {
            foreach (Rigidbody2D rb in passengerrbs)
            {
                platformControllerBelow.AddPassengerRB(rb);
            }
        }
    }