Пример #1
0
    void Awake()
    {
        if (Main != null)
        {
            Debug.LogError("There is already another platPhysics!");
        }

        Main = this;
        Debug.Log($"Instance is {Main}");

        LayerNormal = LayerMask.NameToLayer("LayerNormal");
        LayerGhost  = LayerMask.NameToLayer("LayerGhost");
    }
Пример #2
0
    public void Move(float x, float y)
    {
        _xRemainder += x;
        _yRemainder += y;
        int moveX = Mathf.RoundToInt(_xRemainder);
        int moveY = Mathf.RoundToInt(_yRemainder);

        if (moveX != 0 || moveY != 0)
        {
            UpdateRidingActors();
            enabled = false;

            if (moveX != 0)
            {
                _xRemainder    -= moveX;
                aabb.PositionX += moveX;

                foreach (var actor in PlatPhysics.Main.actors)
                {
                    if (!actor.enabled)
                    {
                        continue;
                    }
                    if (PlatPhysics.CheckAABBVsAABB(aabb, actor.aabb))
                    {
                        if (moveX > 0)
                        {
                            actor.MoveX(aabb.Right - actor.aabb.Left, actor.OnSquish);
                        }
                        else
                        {
                            actor.MoveX(aabb.Left - actor.aabb.Right, actor.OnSquish);
                        }
                    }
                    else if (ridingActors.Contains(actor))
                    {
                        actor.MoveX(moveX, null);
                    }
                }
            }

            if (moveY != 0)
            {
                _yRemainder    -= moveY;
                aabb.PositionY += moveY;

                foreach (var actor in PlatPhysics.Main.actors)
                {
                    if (!actor.enabled)
                    {
                        continue;
                    }
                    if (PlatPhysics.CheckAABBVsAABB(aabb, actor.aabb))
                    {
                        if (moveY > 0)
                        {
                            actor.MoveY(aabb.Top - actor.aabb.Bottom, actor.OnSquish);
                        }
                        else
                        {
                            //NOTE: This is an error probably
                            actor.MoveY(aabb.Bottom - actor.aabb.Top, actor.OnSquish);
                        }
                    }
                    else if (ridingActors.Contains(actor))
                    {
                        actor.MoveY(moveY, null);
                    }
                }
            }

            enabled = true;
        }
    }
Пример #3
0
 private void OnDestroy()
 {
     Main = null;
 }