void OnTriggerEnter2D(Collider2D other) { if((other.CompareTag("Cell") && other.GetType() == typeof(BoxCollider2D)) || (other.CompareTag("Enemy") && other.GetType() == typeof(BoxCollider2D)) || (other.CompareTag("LTAux") && other.GetType() == typeof(BoxCollider2D))){ Vector3 reflect = Vector3.Reflect(other.transform.right, normal); Vector3 direction = new Vector3(reflect.x, reflect.y, 0); Vector3 diff = (other.transform.position + direction) - other.transform.position; /*if((normal.x*diff.x > 0) || (normal.y*diff.y > 0)) return;*/ float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg; AgentMovement agentMovement = other.gameObject.GetComponent<AgentMovement>(); agentMovement.agentRigidbody.rotation = rot_z; //other.gameObject.GetComponent<Rigidbody2D>().AddForce(normal * 10); /*AgentMovement agentMovement = other.gameObject.GetComponent<AgentMovement>(); if(normal.x == 0f){ if(agentMovement.agentRigidbody.position.y >= transform.position.y + offset){ agentMovement.agentRigidbody.position = new Vector2(agentMovement.agentRigidbody.position.x, transform.position.y + offset); } }else{ if(agentMovement.agentRigidbody.position.x >= transform.position.x + offset){ agentMovement.agentRigidbody.position = new Vector2(transform.position.x + offset, agentMovement.agentRigidbody.position.y); } }*/ } }
void OnTriggerExit2D(Collider2D collider){ if(collider.GetType() == typeof(BoxCollider2D)|| collider.GetType() == typeof(EdgeCollider2D)){ colliding = false; } }
void OnTriggerEnter2D(Collider2D coll) { Debug.Log ("Animal coll:" + coll.gameObject.name + " class:" + coll.GetType().FullName); if(coll.gameObject.name.CompareTo("firewall(Clone)") == 0) { GameRuleManager _manager = (GameRuleManager)GameObject.Find("_GameRuleManager(Clone)").GetComponent("GameRuleManager"); _manager.gameOver(); } else if(coll.gameObject.name.StartsWith ("cola_tsubu")) { //cola mituketa! mCount = 50; mTarget = coll.transform; Vector2 heading = mTarget.position - gameObject.transform.position; float distance = heading.magnitude; float force = 0.75f; Vector2 direction = heading / distance * force; rigidbody2D.velocity = direction; // LookAt2D(transform, mTarget, Vector2.up); //cola destroy coll.gameObject.SetActive(false); } else if(coll.gameObject.name.StartsWith ("exit")) { gameObject.SetActive(false); } // }
void OnTriggerExit2D(Collider2D c) { // Debug.Log("an Object collided"); if(objsToRemove.Length > 0){ foreach (GameObject o in objsToRemove){ if(c.GetType() == typeof(BoxCollider2D)){ o.GetComponent<MeshRenderer>().enabled = !o.GetComponent<MeshRenderer>().enabled; } } }else{ if(c.GetType() == typeof(BoxCollider2D)){ objToRemove.GetComponent<MeshRenderer>().enabled = !objToRemove.GetComponent<MeshRenderer>().enabled; } } }
void OnTriggerEnter2D(Collider2D collider){ if(collider.GetType() == typeof(BoxCollider2D)){ LureEnteredMessage message = new LureEnteredMessage (this, collider.gameObject); MessageCenter.Instance.Broadcast (message); npcCaught = true; caughtTime = Time.time; caughtNPC = collider.gameObject; } }
void OnTriggerEnter2D(Collider2D collision) { if(collision.gameObject.layer == playerLayer && collision.gameObject.GetComponent<Rigidbody2D>().velocity.y < -fallthreshold && collision.GetType() == typeof(CircleCollider2D)) { PlatformerCharacter2D playerScript = collision.gameObject.GetComponent<PlatformerCharacter2D>(); playerScript.AdjustHP(-damage); Debug.Log("hit"); } }
void OnTriggerEnter2D(Collider2D other) { if(other.CompareTag("Cell") && other.GetType() == typeof(BoxCollider2D) && color.a > 0.05f){ AgentLife agentLife = other.GetComponent<AgentLife>(); agentLife.TakeDamage(amountDamage); StopCoroutine(agentLife.IsHit(new Color(color.r, color.g, color.b))); StartCoroutine(agentLife.IsHit(new Color(color.r, color.g, color.b))); } }
/// <summary> /// Vérifie ce qui sort dans le percepts de l'agent. /// </summary> /// <param name="other">Other.</param> protected override void OnTriggerExit2D(Collider2D other) { base.OnTriggerExit2D(other); if(other.CompareTag(gameObject.tag) && other.GetType() == typeof(BoxCollider2D)){ if(Vector3.Distance(transform.position, other.transform.position) > GetComponent<CircleCollider2D>().radius){ bacterias.Remove(other.gameObject); } } }
float wallVelocity = 0.0f; //1.2f #endregion Fields #region Methods void OnTriggerEnter2D(Collider2D coll) { Debug.Log ("FireWall coll:" + coll.gameObject.name + " class:" + coll.GetType().FullName); if(coll.gameObject.name.StartsWith ("cola_tsubu")) { wallVelocity = wallUP; //cola destroy coll.gameObject.SetActive(false); } }
void OnTriggerEnter2D(Collider2D col) { Debug.Log ("OutCircle"); if (col.GetType() == typeof(CircleCollider2D)) { rb.velocity = new Vector2(-0.0001f,-0.0001f); rb.angularVelocity = 0; print("circle"); Orc.transform.position=oldPos; // newPos=Vector2.zero; } }
/// <summary> /// Permet de ce diriger vers un macrophage lorsque celui-ci est détecté /// dans le percept du lymphocyte T Auxiliaire et qu'il apporte un résidu. /// </summary> /// <param name="other">Other.</param> protected void OnTriggerStay2D(Collider2D other) { if(other.CompareTag("Cell") && other.GetType() == typeof(BoxCollider2D)){ if(other.name.Contains("Macrophage") && MacrophageAttack.bringResidues){ if(other.GetComponent<Agent>().state == MacrophageAgent.BRING_RESIDUS){ Vector3 diff = other.transform.position - transform.position; float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rot_z); agentRigidbody.velocity = new Vector2(transform.right.x, transform.right.y) * speed * Time.deltaTime; } } } }
/// <summary> /// Vérifie ce qui entre dans le percepts de l'agent. /// </summary> /// <param name="other">Other.</param> protected override void OnTriggerEnter2D(Collider2D other) { base.OnTriggerEnter2D(other); /*if (other.CompareTag ("LTAux") && other.GetType () == typeof(BoxCollider2D)) { if (!targets.Contains (other.gameObject)) { targets.Add (other.gameObject); } }*/ if(other.CompareTag(gameObject.tag) && other.GetType() == typeof(BoxCollider2D)){ if(!bacterias.Contains(other.gameObject)){ bacterias.Add(other.gameObject); } } }
void OnTriggerStay2D(Collider2D col) { if (col.tag == "Player" && col.GetType () == typeof(CircleCollider2D)) { if (upIsStraight) { if (CrossPlatformInputManager.GetAxis("Vertical") < -0.5f) { Active = false; } else { Active = true; } } else { if (CrossPlatformInputManager.GetAxis ("Vertical") > 0.5f) { Active = true; } else { Active = false; } } } }
/// <summary> /// Because Unity does not allow per-collision filtering, the JelloBody.polyCollider.isTrigger is set to true and collision details are /// generated manually. /// </summary> /// <param name="coll">Collider2D that this JelloBody.polyCollider intersected overlaped.</param> private void triggered(Collider2D coll) { // Benchy.Begin("Decide if handle"); if(coll == null) //this happens some times but i dont understand why... return; //only if other body didnt handle this collision bool handle = true; JelloBody otherBody = coll.GetComponent<JelloBody>(); //TODO where does disabled fit in here??? if(mIsTrigger) handle = false; if(otherBody != null) { if(otherBody.IsTrigger || (mIsStatic && otherBody.IsStatic)) handle = false; if(!IsAwake && (!otherBody.IsAwake || otherBody.IsStatic)) handle = false; if(otherBody.IsAwake) { for(int i = 0; i < otherBody.collisions.Count; i++) { if(otherBody.collisions[i].GetOtherBody(otherBody) == this) { handle = false; collisions.Add (otherBody.collisions[i]); break; } } } } else { if(coll.isTrigger) handle = false; if(!IsAwake) { Rigidbody2D rbody = coll.GetComponent<Rigidbody2D>(); if(rbody != null) { if(rbody.IsSleeping()) handle = false; } else { handle = false; } } } // Benchy.End("Decide if handle"); if(handle) { //wake up here? // Benchy.Begin("Wakeup"); //wake any sleeping bodies if need be // float wakeVelocity = 2f; // float wakeAngularVelocity = 2f; if(!mIsAwake) { if(otherBody != null && otherBody.IsAwake) { if(!otherBody.IsKinematic) { if(otherBody.velocity.sqrMagnitude > World.wakeVelocity * World.wakeVelocity || Mathf.Abs( otherBody.angularVelocity ) > World.wakeAngularVelocity) { mIsAwake = true; sleepCount = 0; } } else { mIsAwake = true; sleepCount = 0; } } else { Rigidbody2D rbody = coll.GetComponent<Rigidbody2D>(); if(rbody != null && !rbody.IsSleeping()) { if(rbody.velocity.sqrMagnitude > World.wakeVelocity * World.wakeVelocity || Mathf.Abs( rbody.angularVelocity ) > World.wakeAngularVelocity) { mIsAwake = true; sleepCount = 0; } } } } if(otherBody != null && !otherBody.IsAwake) { if(mIsAwake) { if(!mIsKinematic) //TODO think about using the collision relative velocity in order to wake a body up? { if(velocity.sqrMagnitude > World.wakeVelocity * World.wakeVelocity || Mathf.Abs( angularVelocity ) > World.wakeAngularVelocity) { otherBody.IsAwake = true; otherBody.sleepCount = 0; } } else { otherBody.IsAwake = true; otherBody.sleepCount = 0; } } } // Benchy.End("Wakeup"); SupplementaryColliderInfo Info; bool alreadyTracked = World.StartTrackingCollider(polyCollider, out Info, this); if(alreadyTracked) Info.Update(); SupplementaryColliderInfo otherInfo; alreadyTracked = World.StartTrackingCollider(coll, out otherInfo, otherBody); if(alreadyTracked) otherInfo.Update(); // Benchy.Begin("BodyCollide"); //find fine detail of collision. List<JelloContact> contacts = new List<JelloContact>(); Type t2 = coll.GetType(); if(t2 == typeof(CircleCollider2D)) { World.BodyCollide((CircleCollider2D)coll, Info, ref contacts); } else //polygon and box collisions handled here. { World.BodyCollide (Info, otherInfo, ref contacts); } if(contacts.Count <= 0) return; // Benchy.End("BodyCollide"); // Benchy.Begin("CollisionEvent"); collisions.Add (new JelloCollision(contacts.ToArray())); if(collisions[collisions.Count - 1].GetOtherBody(this) != null) { collisions[collisions.Count - 1].GetOtherBody(this).collisions.Add(collisions[collisions.Count - 1]); collisions[collisions.Count - 1].GetOtherBody(this).OnJelloCollision(collisions[collisions.Count - 1]); } OnJelloCollision(collisions[collisions.Count - 1]); if(collisions[collisions.Count - 1].ignore) return; // Benchy.End("CollisionEvent"); //handle the collision // Benchy.Begin("Resolve"); int numContacts = 0; for(int i = 0; i < collisions[collisions.Count - 1].contacts.Length; i++) { if(!collisions[collisions.Count - 1].contacts[i].ignore) numContacts++; } numContacts = numContacts > 0 ? numContacts : 1; //Debug.Log (numContacts); for(int i = 0; i < collisions[collisions.Count - 1].contacts.Length; i++) { if(collisions[collisions.Count - 1].contacts[i].ignore) continue; collisions[collisions.Count - 1].contacts[i].numContacts = numContacts; World.ApplyCollisionImpulse(collisions[collisions.Count - 1].contacts[i]); } // Benchy.End("Resolve"); //TODO take into account circle collider collisions //TODO do this with velocities as well? for(int i = 0; i < Info.largestMTVs.Length; i++) { Vector2 mtv = Info.largestMTVs[i]; if(mtv != Vector2.zero) { mEdgePointMasses[i].Position += Info.largestMTVs[i]; //mEdgePointMasses[i].Position += Info.numEngagments[i] != 0 ? Info.largestMTVs[i] / Info.numEngagments[i] : Info.largestMTVs[i]; Info.UpdateCollisionInfo(i, mEdgePointMasses[i].Position, Vector2.zero); Info.largestMTVs[i] = Vector2.zero; } if(Info.numEngagments[i] != 0) mEdgePointMasses[i].velocity += Info.queuedVelocities[i] / Info.numEngagments[i]; Info.numEngagments[i] = 0; Info.queuedVelocities[i] = Vector2.zero; } if(otherInfo != null && otherInfo.body != null) { for(int i = 0; i < otherInfo.largestMTVs.Length; i++) { Vector2 mtv = otherInfo.largestMTVs[i]; if(mtv != Vector2.zero) { otherInfo.body.getEdgePointMass(i).Position += otherInfo.largestMTVs[i]; //otherInfo.body.getEdgePointMass(i).Position += otherInfo.numEngagments[i] != 0 ? otherInfo.largestMTVs[i] / otherInfo.numEngagments[i] : otherInfo.largestMTVs[i]; otherInfo.UpdateCollisionInfo(i, otherInfo.body.getEdgePointMass(i).Position, Vector2.zero); otherInfo.largestMTVs[i] = Vector2.zero; } if(otherInfo.numEngagments[i] != 0) otherInfo.body.getPointMass(i).velocity += otherInfo.queuedVelocities[i] / otherInfo.numEngagments[i]; otherInfo.queuedVelocities[i] = Vector2.zero; otherInfo.numEngagments[i] = 0; } } else//make work with circles... { Vector2 mtv = otherInfo.largestMTVs[0]; if(mtv != Vector2.zero) //for some reason this stops any more triggers from occuring. this could cause issues when a static jello body hits this and another non static jello body hits it in one frame. { otherInfo.transform.position += (Vector3)mtv; otherInfo.UpdateCollisionInfo(0, Vector2.zero, mtv); otherInfo.largestMTVs[0] = Vector2.zero; } //TODO handle with numengagments as well. // int num = 0; // Vector2 totalVelocity = Vector2.zero; // float totalAngularVelocity = 0f; // for(int i = 0; i < otherInfo.queuedVelocities.Length; i++) // { // if(otherInfo.numEngagments[i] != 0) // { // float invNum = 1 / otherInfo.numEngagments[i]; // // otherInfo.queuedVelocities[i] *= invNum; // totalVelocity += otherInfo.queuedVelocities[i]; // // otherInfo.queuedAngularVelocities[i] *= invNum; // totalAngularVelocity += otherInfo.queuedAngularVelocities[i]; // // otherInfo.numEngagments[i] = 0; // otherInfo.queuedVelocities[i] = Vector2.zero; // otherInfo.queuedAngularVelocities[i] = 0f; // num++; // } // } // // if(num != 0) // { // float invNum = 1 / num; // otherInfo.collider2D.rigidbody2D.velocity += totalVelocity * invNum; // otherInfo.collider2D.rigidbody2D.angularVelocity += totalAngularVelocity *invNum; // } } } }
void OnTriggerEnter2D(Collider2D collider){ if(collider.GetType() == typeof(BoxCollider2D)|| collider.GetType() == typeof(EdgeCollider2D)){ colliding = true; } }
void OnTriggerExit2D(Collider2D col2d) { Debug.Log("GameManager: OnTriggerExit2D:" + col2d.GetType()); }
void OnTriggerEnter2D(Collider2D other) { if ((other.CompareTag ("Human") || other.CompareTag ("Body")) && !targets.Contains(other.gameObject) && other.GetType ().Equals (typeof(BoxCollider2D))) { targets.Add (other.gameObject); } }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag( "Player") && other.GetType() == typeof(EdgeCollider2D) ){ other.GetComponent<CharacterMovement> ().Drown (); } }
/// <summary> /// Vérifie ce qui sort dans le percepts de l'agent. /// </summary> protected virtual void OnTriggerExit2D(Collider2D other) { if(other.CompareTag(tagEnemy) && other.GetType() == typeof(BoxCollider2D)){ if(Vector3.Distance(transform.position, other.transform.position) >= GetComponent<CircleCollider2D>().radius){ targets.Remove(other.gameObject); } } }
/// <summary> /// Vérifie ce qui entre dans le percepts de l'agent. /// </summary> protected virtual void OnTriggerEnter2D(Collider2D other) { if(other.CompareTag(tagEnemy) && other.GetType() == typeof(BoxCollider2D)){ if(!targets.Contains(other.gameObject)){ targets.Add(other.gameObject); } } }