Exemplo n.º 1
0
        public List <JCollider> FindOverlaps(JCollider colliderA)
        {
            var output  = new List <JCollider>(10);
            var boundsA = colliderA.meshFrame.AABB;
            var meshA   = colliderA.meshFrame;

            collisionMapQueue.ResetQueueIteration();
            while (collisionMapQueue.HasNext())
            {
                var map = collisionMapQueue.Next();
                if (map.bodies != null && JMeshOverlap.AABBOverlap(boundsA, map.bounds))
                {
                    for (var i = 0; i < map.bodies.Count; i++)
                    {
                        var colliderB = map.bodies[i];
                        if (output.Contains(colliderB))
                        {
                            continue;
                        }

                        if (JLayerMaskUtil.MaskCheck(JLayerMaskUtil.GetLayerMask(colliderA.jLayer), colliderB.jLayer) &&
                            JMeshOverlap.AABBOverlap(boundsA, colliderB.meshFrame.AABB) &&
                            JMeshOverlap.MeshesOverlap(meshA, colliderB.meshFrame))
                        {
                            output.Add(colliderB);
                        }
                    }
                }
            }

            return(output);
        }
Exemplo n.º 2
0
        // Modifies completedCollisions by always trying to add the new collision pair to the list
        private bool ShouldSkipCollisionCheck(JCollider colliderA, JCollider colliderB, HashSet <JCollisionPair> completedCollisions)
        {
            if (!JLayerMaskUtil.MaskCheck(JLayerMaskUtil.GetLayerMask(colliderA.jLayer), colliderB.jLayer))
            {
                return(true);
            }

            var collisionPair = new JCollisionPair(colliderA, colliderB);

            if (!completedCollisions.Add(collisionPair))    // This is where the methods mutates completedCollisions
            {
                return(true);
            }

            var boundsA = colliderA.meshFrame.AABB;
            var boundsB = colliderB.meshFrame.AABB;

            if (!JMeshOverlap.AABBOverlap(boundsA, boundsB))
            {
                return(true);
            }

            var meshA = colliderA.meshFrame;
            var meshB = colliderB.meshFrame;

            if (!JMeshOverlap.MeshesOverlap(meshA, meshB))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        private void Push(JCollider pushable, JCollider pushingFrom, Vector3 pushDirection, float magnitude)
        {
            var centerDirection     = pushable.meshFrame.AABB.center - pushingFrom.meshFrame.AABB.center;
            var pushScalarDirection = Vector3.Dot(pushDirection, centerDirection);

            pushScalarDirection /= Mathf.Abs(pushScalarDirection);

            var actualPushDirection = pushDirection * pushScalarDirection;
            var pushVector          = actualPushDirection * magnitude;

            pushable.transform.Translate(pushVector, Space.World);
            pushPairs.Add(new JCollisionPushPair(pushable, pushingFrom, new Push(actualPushDirection, magnitude)));
        }
Exemplo n.º 4
0
        private void HandlePushResult(Push pushResult, JCollider colliderA, JCollider colliderB)
        {
            if (colliderA.IsStationary || colliderB.IsStationary)
            {
                var pushable    = colliderA.IsStationary ? colliderB : colliderA;
                var nonPushable = colliderA.IsStationary ? colliderA : colliderB;
                Push(pushable, nonPushable, pushResult.Direction, pushResult.Magnitude);
            }
            else
            {
                var halfMagnitude = pushResult.Magnitude / 2f;

                Push(colliderA, colliderB, pushResult.Direction, halfMagnitude);
                Push(colliderB, colliderA, pushResult.Direction, halfMagnitude);
            }
        }
Exemplo n.º 5
0
 public bool Remove(JCollider collider)
 {
     return(allCollidersInScene.Remove(collider));
 }
Exemplo n.º 6
0
 public bool Add(JCollider collider)
 {
     return(allCollidersInScene.Add(collider));
 }
Exemplo n.º 7
0
 public void OnJCollsionExit(JCollider otherCollider)
 {
     onExitHandler?.Invoke(this, otherCollider);
 }
Exemplo n.º 8
0
 public void OnJCollisionEnter(JCollider otherCollider)
 {
     onEnterHandler?.Invoke(this, otherCollider);
 }
Exemplo n.º 9
0
 public void OnJCollsionStay(JCollider otherCollider)
 {
     onStayHandler?.Invoke(this, otherCollider);
 }