void OnTriggerExit2D(Collider2D _other) { if (_other.GetInstanceID() == m_DeadzoneColliderID) { // Debug.Log("Projectile leaved deadzone. Activate."); GetComponent<Projectile>().Activate(); Destroy(this); } }
void OnTriggerEnter2D(Collider2D other) { IndicatorArrow arrowClone = Instantiate (arrow, new Vector3(parent.transform.position.x,parent.transform.position.y,arrow.transform.position.z), arrow.transform.rotation) as IndicatorArrow; arrowClone.transform.parent = parent.transform; arrowClone.target = other.gameObject; arrowClone.fromPos = parent; // arrowClone.rotate(); arrowClone.maxRange = range; arrows[other.GetInstanceID ()] = arrowClone; }
public void Set(UnityEngine.Collider2D source, int phase, float thickness) { boundsMin = source.bounds.min - Vector3.one * (thickness + 0.01f); //allow some room for contacts to be generated before penetration. boundsMax = source.bounds.max + Vector3.one * (thickness + 0.01f); translation = source.transform.position; rotation = source.transform.rotation; scale = source.transform.lossyScale; contactOffset = thickness; this.collisionGroup = phase; this.trigger = source.isTrigger; this.id = source.GetInstanceID(); }
void OnTriggerEnter2D(Collider2D c) { var layerName = LayerMask.LayerToName (c.gameObject.layer); switch (layerName) { case "Enemy": if( colliderIdList.Contains(c.GetInstanceID() ) ) { return; } c.BroadcastMessage("Damage"); //if( !isMultiHit ) colliderIdList.Add (c.GetInstanceID()); break; case "EnemyBullet": Destroy(c.gameObject); break; default: break; } }
// Esquive des tirs du joueur private void DodgeBullet() { detectedBullet = Physics2D.OverlapArea (new Vector2 (myTransform.position.x - 1, myTransform.position.y + 0.5f), new Vector2 (myTransform.position.x - 2.5f, myTransform.position.y - 1), playerMask); // Si une balle entre dans la zone derrière la poule if (detectedBullet != null && detectedBullet.CompareTag("Bullet")) { // On retient la dernière balle prise en compte, pour éviter d'appeler en boucle la même fonction if (currentBulletID != detectedBullet.GetInstanceID ()) { currentBulletID = detectedBullet.GetInstanceID (); entryTime = TimeManager.time; // On retient le moment de l'entrée dans la zone, pour reset au bout de 2sec si jamais il ne se passe rien (voir plus bas) // On compare à la probabilité d'esquiver if (Random.Range(0f, 1f) < dodgeSkill) { // On ajuste la puissance du saut en fonction du lieu d'impact de la balle float powerJump = Mathf.Clamp(detectedBullet.transform.position.y, 1.5f, 2); // On fait sauter la poule myRb.velocity = new Vector2 (myRb.velocity.x, powerJump * jumpHeight); } } } if (TimeManager.time > entryTime + 2) { currentBulletID = 0; } }
/// <summary> /// Stop tracking the Collider2D. /// </summary> /// <param name="collider">The Collider2D to stop tracking.</param> public void StopTrackingCollider(Collider2D collider) { if(!trackedColliders.Contains(collider)) return; trackedColliders.Remove(collider); TrackedColliderDictionary.Remove(collider.GetInstanceID()); }
/// <summary> /// Start tracking the Collider2D. /// Adds it to the JelloWorld.trackedColliders list and JelloWorld.TrackedColliderDictionary. /// </summary> /// <param name="collider">The Collider2D to start tracking.</param> /// <param name="colliderInfo">The SupplementaryColliderInfo that describes the now tracked Collider2D.</param> /// <param name="jelloBody">The JelloBody, if any, the Collider2D belongs to.</param> /// <returns>Whether the collider is already being tracked. True if already being tracked, false if not.</returns> public bool StartTrackingCollider(Collider2D collider, out SupplementaryColliderInfo colliderInfo, JelloBody jelloBody = null) { if(trackedColliders.Contains(collider)) { colliderInfo = World.TrackedColliderDictionary[collider.GetInstanceID()]; return true; } trackedColliders.Add (collider); colliderInfo = new SupplementaryColliderInfo(collider, jelloBody); TrackedColliderDictionary.Add (collider.GetInstanceID(), colliderInfo); return false; }
/// <summary> /// Start tracking the Collider2D. /// Adds it to the JelloWorld.trackedColliders list and JelloWorld.TrackedColliderDictionary. /// </summary> /// <param name="collider">The Collider2D to start tracking.</param> /// <param name="jelloBody">The JelloBody, if any, the Collider2D belongs to.</param> public void StartTrackingCollider(Collider2D collider, JelloBody jelloBody = null) { if(trackedColliders.Contains(collider)) return; trackedColliders.Add (collider); TrackedColliderDictionary.Add (collider.GetInstanceID(), new SupplementaryColliderInfo(collider, jelloBody)); }
void OnTriggerExit2D(Collider2D other) { Destroy (arrows[other.GetInstanceID()].gameObject, 0); arrows.Remove (other.GetInstanceID ()); }
void OnTriggerEnter2D(Collider2D c) { isCollided(c.GetInstanceID(), c.gameObject); //Debug.Log("Enter "+this.gameObject.GetInstanceID() + " " +c.gameObject.GetInstanceID()); //transform.position = new Vector3(0, -100, 0); }
private void GrabFunction(Collider2D other) { #region Cancel grab if one of these conditions is true (id, dist, yUpSpeed) // The id is used to make sure it can actually leave the grab state // and not regrab immediately int id = other.GetInstanceID(); if (id == lastGrabbedID) return; // Makes sure its not to far down? float yDist = Grab.position.y - other.transform.position.y; if (yDist + GrabSettings.GrabMinNegYDist < 0) return; // If the upvelocity is too high, it will pass till falling down if (rigid.velocity.y > GrabSettings.MaxYVelocity) return; #endregion // Grab the object by translation Vector3 relPos = other.transform.position - tr.position; float dir = Mathf.Sign(relPos.x); Vector3 offset = GrabOffset; offset.x *= dir; Vector3 newPos = other.transform.position - offset; tr.position = newPos; // Change the state SetState(PlayerState.Grabbing); lastGrabbedID = id; // Can walljump in any direction after grabbing resetWallJump(); // Make sure the animation clip is facing the right direction CheckFlipBy(dir); }