Beispiel #1
0
        void PopulateCollisionData(AABB colliderA, AABB colliderB)
        {
            // initialise collision data variables
            currentCollisionPair = new List <CollisionPair>();
            colPair           = new CollisionPair();
            colPair.m_ObjectA = colliderA;
            colPair.m_ObjectB = colliderB;

            // calculate the penetration depth between the 2 colliders
            CalcPenetration(colliderA, colliderB);

            // check which axis has the least amount of penetration
            if (Mathf.Abs(xDirection) < Mathf.Abs(yDirection))
            {
                //point the collision normal either left or right depending on the sign
                colPair.m_CollisionNormal = new Vector2(Mathf.Sign(xDistance), 0);
                colPair.m_CollisionPoint  = new Vector2(colliderA.transform.position.x
                                                        + (colliderA.m_Width * Mathf.Sign(xDistance)),
                                                        colliderB.transform.position.y);
            }
            else
            {
                // point the collision normal up or down depending on the sign
                colPair.m_CollisionNormal = new Vector2(0, Mathf.Sign(yDistance));
                colPair.m_CollisionPoint  = new Vector2(colliderA.transform.position.x
                                                        + (colliderA.m_Width * Mathf.Sign(xDistance)),
                                                        colliderB.transform.position.y);
            }

            // add the final depth to collision data
            colPair.m_PenetrationDepth = new Vector2(xDirection, yDirection);

            currentCollisionPair.Add(colPair);

            // resolve the current collision based on the data we found
            ResolveCollisionPair(currentCollisionPair);

            //TODO: change to private
            depthX     = 0f;
            depthY     = 0f;
            xDistance  = 0f;
            yDistance  = 0f;
            xDirection = 0f;
            yDirection = 0f;
        }
Beispiel #2
0
        public void InitPhysicsManager()
        {
            //find all colliders in the scene A$AP
            boxList = GameObject.FindGameObjectsWithTag("Ground");
            for (int i = 0; i < boxList.Length; i++)
            {
                floorBoundingBoxes.Add(boxList[i].GetComponent <AABB>());
            }
            boxList = null;
            boxList = GameObject.FindGameObjectsWithTag("Entity");
            for (int i = 0; i < boxList.Length; i++)
            {
                entityBoundingBoxes.Add(boxList[i].GetComponent <AABB>());
            }
            // add player collider
            entityBoundingBoxes.Add(GameObject.FindGameObjectWithTag("Player").GetComponent <AABB>());

            boxList = null;
            boxList = GameObject.FindGameObjectsWithTag("Boundary");
            for (int i = 0; i < boxList.Length; i++)
            {
                boundaryBoundingBoxes.Add(boxList[i].GetComponent <AABB>());
            }
            // initialise collision data
            colPair = new CollisionPair();

            // initialise all rigidbodies in scene
            InitRigidbodiesInScene();

            // initialise nav graph
            grid = GetComponent <NavGraph>();
            grid.InitGraph();

            chargeRate = 0;
            chargeDmg  = 0;

            dPath = new List <Vector2>();
        }
Beispiel #3
0
 /// <summary>
 /// Handle specific actions relative to collisions
 /// </summary>
 /// <param name="col"></param>
 public virtual void OnCollision(CollisionPair col)
 {
     //Do Nothing
 }