Exemple #1
0
        public void OnImmediateCollisionStay(CollisionChild col)
        {
            IEnumerator <Behaviour> en = behaviours.GetEnumerator();

            while (en.MoveNext())
            {
                Behaviour cur = en.Current;
                if (cur.active)
                {
                    cur.OnImmediateCollisionStay(col);
                }
            }
        }
Exemple #2
0
        public void Add(CollisionChild cc)
        {
            ColliderPair cp = new ColliderPair(cc.self, cc.other);

            if (childs.ContainsKey(cp))
            {
                childs [cp].Add(cc);
            }
            else
            {
                List <CollisionChild> ccs = new List <CollisionChild> ();
                childs [cp] = ccs;
                ccs.Add(cc);
            }
            cc.t = cc.self.t + (1 - cc.self.t) * cc.t;
        }
Exemple #3
0
		public void ImmediateCollisionBroadcast(CollisionChild col)
		{
			if (prevCollisions.ContainsKey(col.other))
			{
				Transform t;
				for (t = transform; t.gameObject.rigidbody != this.rigidbody; t = t.parent)
				{
					t.gameObject.OnImmediateCollisionStay(col);
				}
				t.gameObject.OnImmediateCollisionStay(col);
				
			}
			else
			{
				Transform t;
				for (t = transform; t.gameObject.rigidbody != this.rigidbody; t = t.parent)
				{
					t.gameObject.OnImmediateCollisionEnter(col);
				}
				t.gameObject.OnImmediateCollisionEnter(col);
			}
		}
Exemple #4
0
 public void BuildAndBroadcast()
 {
     foreach (KeyValuePair <ColliderPair, List <CollisionChild> > kvp in childs)
     {
         ColliderPair          key = kvp.Key;
         List <CollisionChild> ccs = kvp.Value;
         //ccs.Sort ((a, b) => a.t.CompareTo (b.t));
         int       l   = ccs.Count;
         Collision col = new Collision(key.self, key.other,
                                       new Vector2[l], new Vector2[l], new Vector2[l], new float[l]);
         int i = 0;
         IEnumerator <CollisionChild> en = ccs.GetEnumerator();
         while (en.MoveNext())
         {
             CollisionChild cc = en.Current;
             col.contactPoints [i]  = cc.contactPoint;
             col.depenetrations [i] = cc.depenetration;
             col.normals [i]        = cc.normal;
             col.ts [i]             = cc.t;
             ++i;
         }
         key.self.AddCollision(col);
     }
 }
Exemple #5
0
 public virtual void OnImmediateCollisionStay(CollisionChild col)
 {
 }
Exemple #6
0
 public virtual void OnImmediateCollisionEnter(CollisionChild col)
 {
 }
        public CollisionApplication(CollisionChild c)
        {
            source = c;
            Vector2 velocity = c.self.velocity;

            movementChange    = Vector2.zero;
            velocityChange    = Vector2.zero;
            isGroundedGravity = false;
            isGroundedUp      = false;
            isGroundedDown    = false;
            isGroundedLeft    = false;
            isGroundedRight   = false;
            applicable        = c.self.rigidbody != null;     // && c.depenetration != Vector2.zero;
            if (!applicable)
            {
                return;
            }
            movementChange = c.depenetration - c.movement;
            positionChange = c.movement;

            /*int l = source.normals.Length;
             * for(int k = 0; k < l; ++k){*/
            Vector2 norm = source.normal.normalized;
            float   selfVelocityNormalDot = Vector2.Dot(velocity.normalized, norm);

            if (selfVelocityNormalDot < 0)
            {
                Vector2 a = Util.Project(velocity, norm);
                Vector2 b = Util.Project(source.other.velocity, norm);
                if (Vector2.Dot(a, b) > 0)
                {
                    if (a.sqrMagnitude > b.sqrMagnitude)
                    {
                        velocityChange -= a - b;
                    }
                }
                else
                {
                    velocityChange -= a;
                }
            }
            //}
            Rigidbody rb = source.self.rigidbody;

            velocityChange = Util.Clamp(rb._velocity + velocityChange, rb._velocity, Vector2.zero) - rb._velocity;
            //}
            //for(int k = 0; k < l; ++k){
            if (source.self.gameObject.name == "GreenBox" && source.other.gameObject.name == "WhiteBox")
            {
                //if (norm.y > 0) {
                UnityEngine.Debug.Log("NORM " + Util.ToString(norm));
                //}
            }
            Vector2 selfDepNorm = norm;

            if (Vector2.Dot(selfDepNorm, source.self.physics.negativeNormalizedGravity) >= Rigidbody.groundMinimumCos)
            {
                isGroundedGravity = true;
            }
            if (Vector2.Dot(selfDepNorm, source.self.transform.down) >= Rigidbody.groundMinimumCos)
            {
                isGroundedUp = true;
            }
            if (Vector2.Dot(selfDepNorm, source.self.transform.up) >= Rigidbody.groundMinimumCos)
            {
                isGroundedDown = true;
            }
            if (Vector2.Dot(selfDepNorm, source.self.transform.right) >= Rigidbody.groundMinimumCos)
            {
                isGroundedLeft = true;
            }
            if (Vector2.Dot(selfDepNorm, source.self.transform.left) >= Rigidbody.groundMinimumCos)
            {
                isGroundedRight = true;
            }
            //}
        }