Ejemplo n.º 1
0
        private int SortByMovedDistance(RigidEntity a, RigidEntity b)
        {
            var val = a.MovedDistance.CompareTo(b.MovedDistance);

            if (val == 0)
            {
                return(SortByY(a, b));
            }
            else
            {
                return(val);
            }
        }
Ejemplo n.º 2
0
        public bool CheckCollision(RigidEntity col, out Vector3 colliderPosition)
        {
            bool x = maxVector.X > col.minVector.X && minVector.X < col.maxVector.X;
            bool y = maxVector.Y > col.minVector.Y && minVector.Y < col.maxVector.Y;
            bool z = maxVector.Z > col.minVector.Z && minVector.Z < col.maxVector.Z;

            if (x && y && z)
            {
                colliderPosition = GetColliderPosition(col);
            }
            else
            {
                colliderPosition = col.gameObject.transform.position;
            }

            return(x && y && z);
        }
Ejemplo n.º 3
0
 private int SortByY(RigidEntity a, RigidEntity b)
 {
     return(a.gameObject.transform.position.Y.CompareTo(b.gameObject.transform.position.Y));
 }
Ejemplo n.º 4
0
        private Vector3 GetColliderPosition(RigidEntity col)
        {
            float finalX = 0;
            float finalY = 0;
            float finalZ = 0;

            float colX = 0;
            float colY = 0;
            float colZ = 0;

            var directionState = GetDirectionState(col.GetEntityDirection());

            if (directionState.X != Direction.None)
            {
                if (col.minVector.X < maxVector.X && directionState.X == Direction.Negative)
                {
                    colX   = Math.Abs(maxVector.X - col.minVector.X);
                    finalX = maxVector.X + (col.maxVector.X - col.minVector.X) / 2 + (col.minVector.X * col.weight.X) / 2;
                }
                else if (col.maxVector.X > minVector.X && directionState.X == Direction.Positive)
                {
                    colX   = Math.Abs(col.maxVector.X - minVector.X);
                    finalX = minVector.X - (col.maxVector.X - col.minVector.X) / 2 + (col.maxVector.X * col.weight.X) / 2;
                }
            }
            if (directionState.Y != Direction.None)
            {
                if (col.minVector.Y < maxVector.Y && directionState.Y == Direction.Negative)
                {
                    colY   = Math.Abs(maxVector.Y - col.minVector.Y);
                    finalY = maxVector.Y + (col.maxVector.Y - col.minVector.Y) / 2 + (col.minVector.Y * col.weight.Y) / 2;
                }
                else if (col.maxVector.Y > minVector.Y && directionState.Y == Direction.Positive)
                {
                    colY   = Math.Abs(col.maxVector.Y - minVector.Y);
                    finalY = minVector.Y - (col.maxVector.Y - col.minVector.Y) / 2 + (col.maxVector.Y * col.weight.Y) / 2;
                }
            }

            if (directionState.Z != Direction.None)
            {
                if (col.minVector.Z < maxVector.Z && directionState.Z == Direction.Negative)
                {
                    colZ   = Math.Abs(maxVector.Z - col.minVector.Z);
                    finalZ = maxVector.Z + (col.maxVector.Z - col.minVector.Z) / 2 + (col.minVector.Z * col.weight.Z) / 2;
                }
                else if (col.maxVector.Z > minVector.Z && directionState.Z == Direction.Positive)
                {
                    colZ   = Math.Abs(col.maxVector.Z - minVector.Z);
                    finalZ = minVector.Z - (col.maxVector.Z - col.minVector.Z) / 2 + (col.maxVector.Z * col.weight.Z) / 2;
                }
            }

            if (colX == 0)
            {
                finalX = col.gameObject.transform.position.X;
            }
            else if (colY != 0 && colX > colY || colZ != 0 && colX > colZ)
            {
                finalX = col.gameObject.transform.position.X;
            }

            if (colY == 0)
            {
                finalY = col.gameObject.transform.position.Y;
            }
            else if (colX != 0 && colY > colX || colZ != 0 && colY > colZ)
            {
                finalY = col.gameObject.transform.position.Y;
            }

            if (colZ == 0)
            {
                finalZ = col.gameObject.transform.position.Z;
            }
            else if (colX != 0 && colZ > colX || colY != 0 && colZ > colY)
            {
                finalZ = col.gameObject.transform.position.Z;
            }

            return(new Vector3(finalX, finalY, finalZ));
        }