private void NotifyCollision(PlayerController player) { if (OnCollision != null) { OnCollision.Invoke(player); } }
private void Update() { _lineRenderer.SetPosition(0, transform.position); var ray = new Ray(transform.position, transform.forward); var point = transform.TransformPoint(new Vector3(0, 0, maxLaserLen)); var raycastHits = Physics.RaycastAll(ray, maxLaserLen).ToList(); raycastHits.Sort((a, b) => a.distance.CompareTo(b.distance)); if (raycastHits.Count > 0) { foreach (var hit in raycastHits) { LaserReceiverData receiver = null; if (hit.collider && (receiver = hit.collider.GetComponent <LaserReceiverData>()) && !receiver.receiveLaser) { continue; } point = hit.point; OnCollision?.Invoke(hit.collider); if (receiver) { receiver.OnCollisionWithLaser(this); } break; } } _lineRenderer.SetPosition(1, point); }
private void FixedUpdate() { foreach (var particle in Manager.Particles) { OnCollision.Invoke(particle); } }
void OnCollisionEnter(Collision col) { if (OnCollision != null) { OnCollision.Invoke(col); } }
private void LateUpdate() { if (_wasCollisionDetected) { return; } RaycastHit hit; if (!Physics.Raycast(_transform.position + transform.forward, transform.forward, out hit, RayCastRange)) { return; } var point = hit.point; var distance = Vector3.Distance(point, _transform.position); if (distance > Distance) { return; } _wasCollisionDetected = true; if (OnCollision != null) { OnCollision.Invoke(new CollisionPoint { Point = hit.point, Normal = hit.normal }); } }
public void FixedUpdate() { var thisContains = false; foreach (var particle in manager.Around(Position, ScaledSize)) { Vector2 halfSize = ScaledSize / 2; Vector2 direction = particle.particleInfo.Position - Position; direction.x = Mathf.Abs(direction.x); direction.y = Mathf.Abs(direction.y); if (direction.x < halfSize.x && direction.y < halfSize.y) { OnCollision.Invoke(particle); thisContains = true; } } if (thisContains ^ lastContains) { if (thisContains) { OnContains.Invoke(); } else { OnContainsNot.Invoke(); } } lastContains = thisContains; }
private void OnTriggerEnter2D(Collider2D collision) { if (canContact) { OnCollision.Invoke(this); } }
private float HorizontalCollisions(Vector2 velocity) { var direction = Mathf.Sign(velocity.x); var distance = Mathf.Abs(velocity.x - skinWidth); var x = direction < 0 ? Collider.bounds.min.x + skinWidth : Collider.bounds.max.x - skinWidth; Vector2 rayOrigin = new Vector2(x, Collider.bounds.center.y); if (debugRays) { Debug.DrawRay(rayOrigin, direction * distance * Vector2.right, Color.green); } var hit = Physics2D.Raycast(rayOrigin, Vector2.right * direction, distance, cameraLayer); if (hit) { if (ShouldIgnoreCollisions(hit.collider.gameObject)) { return(velocity.x); } velocity.x = (hit.distance - skinWidth) * direction; collisions.Left = direction == -1; collisions.Right = direction == 1; OnCollision?.Invoke(hit.collider.gameObject); } return(velocity.x); }
private float VerticalCollisions(Vector2 velocity) { var direction = Mathf.Sign(velocity.y); var distance = Mathf.Abs(velocity.y - skinWidth); var y = direction < 0 ? Collider.bounds.min.y + skinWidth : Collider.bounds.max.y - skinWidth; Vector2 rayOrigin = new Vector2(Collider.bounds.center.x, y); var hit = Physics2D.Raycast(rayOrigin, Vector2.up * direction, distance, cameraLayer); if (debugRays) { Debug.DrawRay(rayOrigin, direction * distance * Vector2.up, Color.green); } if (hit) { if (ShouldIgnoreCollisions(hit.collider.gameObject)) { return(velocity.y); } velocity.y = (hit.distance - skinWidth) * direction; collisions.Below = direction == -1; collisions.Above = direction == 1; OnCollision?.Invoke(hit.collider.gameObject); } return(velocity.y); }
public void HandleCollision(GameSession gameSession, ColliderInfo collidedInfo, ColliderInfo colliderInfo, Vector2 collisionPosition, bool amCollided) { lock (CollisionCooldownLock) { //Check for existing collision cooldown bool inCooldown = false; for (int i = 0; i < collisionCooldowns.Count; i++) { if (collisionCooldowns[i].collidedInfo.clientIndex == collidedInfo.clientIndex && collisionCooldowns[i].collidedInfo.entityIndex == collidedInfo.entityIndex && collisionCooldowns[i].colliderInfo.clientIndex == colliderInfo.clientIndex && collisionCooldowns[i].colliderInfo.entityIndex == colliderInfo.entityIndex) { inCooldown = true; break; } } if (!inCooldown) { //Add collision cooldown collisionCooldowns.Add(new CollisionCooldown(gameSession.LatestGameTime.TotalGameTime.TotalMilliseconds, colliderInfo, collidedInfo)); //Handle collision OnCollision.Invoke(gameSession, collidedInfo, colliderInfo, collisionPosition, amCollided); } else { return; } } }
void OnTriggerEnter2D(Collider2D collision) { Log.Message("Столкновение с " + collision.name); Color partColor = Color.black; Color orbColor = GetComponent <SpriteRenderer>().color; PartFlashing partFlashing = null; if (!collision.TryGetComponent(out partFlashing)) { Log.Error("Не удалось получить компонент PartFlashing части формы: " + collision.name); } else { partColor = partFlashing.PartColor; } try { CollisionData collisionData = new CollisionData(partColor, orbColor, partFlashing); OnCollision?.Invoke(collisionData); } catch { Log.Warning("Обработка ошибки генерации данных о колизии."); Debug.Break(); } Log.Message("Уничтожение сферы."); Destroy(gameObject); }
public virtual void RaiseCollision(ColliderComponent other) { if (OnCollision != null) { OnCollision.Invoke(other); } }
private void OnTriggerEnter(Collider other) { if (other.gameObject == collideWith) { onCollision.Invoke(true); } }
private void OnCollisionEnter(Collision collision) { if (!IsRunning) { return; } if (_wasCollided && IsSingleCollisionMode) { return; } foreach (var contact in collision.contacts) { if (!_wasCollided) { _wasCollided = true; } if (OnCollision != null) { OnCollision.Invoke(new SFX_CollisionPoint { Point = contact.point, Normal = contact.normal }); } } }
private void LateUpdate() { if (!IsRunning) { return; } if (IsSingleCollisionMode && _wasCollided) { return; } bool wasCollided = false; Vector3 point = Vector3.zero; Vector3 normal = Vector3.zero; switch (DistanceMode) { case DistanceComparisonMode.Target: var distance = Vector3.Distance(_transform.position, TargetPosition); if (distance <= CollisionDistance) { wasCollided = true; point = TargetPosition; } break; case DistanceComparisonMode.Raycast: RaycastHit hit; if (Physics.Raycast(_transform.position, _transform.forward, out hit, CollisionDistance)) { wasCollided = true; point = hit.point; normal = hit.normal; } break; } if (!wasCollided) { return; } if (!_wasCollided) { _wasCollided = true; } if (OnCollision != null) { OnCollision.Invoke(new SFX_CollisionPoint { Point = point, Normal = normal }); } }
private void RunSolidLogic(object objParent, CollisionType type, CollisionResolutionData data) { OnCollision?.Invoke(objParent, new CollisionEventArgs("") { CType = type, TStyle = TriggerStyle.None, CData = data }); }
private void EventLogic(object obj, CollisionType type, TriggerStyle style, CollisionResolutionData data = new CollisionResolutionData()) { OnCollision?.Invoke(obj, new CollisionEventArgs("") { CType = type, TStyle = style, CData = data }); }
private void OnTriggerEnter2D(Collider2D collision) { if (canContact) { var damageDealer = collision.GetComponent <DamageDealer>(); OnCollision.Invoke(this, damageDealer.damage); } }
void FixedUpdate() { foreach (var particle in manager.Around(Position, new Vector2(1, 1) * (Radius + manager.Param.Radius))) { if (Vector2.Distance(particle.particleInfo.Position, Position) <= Radius + manager.Param.Radius) { OnCollision.Invoke(particle); } } }
private void OnCollisionEnter(Collision other) { bool interaction = LayerUtils.IsLayer(other.gameObject.layer, interactionMask); if (!interaction) { return; } OnCollision?.Invoke(other.gameObject); }
/** * Called when the player hits something *@param collision - collision info */ void OnCollisionEnter(Collision collision) { // is view disabled? if (!Enabled) { return; } // get back the previous sounds to play OnCollision?.Invoke(this, RigidBody, Collider, collision); }
void OnCollisionEnter2D(Collision2D other) { var component = other.gameObject.GetComponent <T>(); if (component == null) { return; } OnCollision?.Invoke(component); }
private void Check(Actor other, GameTime gameTime) { //Checa a colisão var result = Collision.ActorCollision(Actor, other); if (result.HasCollided) { //O que fazer sobre a colisão será definido pelo usuário. OnCollision?.Invoke(Actor, other, gameTime, result); } }
void OnCollisionEnter2D(Collision2D collision) { if (collision.collider.GetComponent <Tile>()) { OnCollision?.Invoke(this, EventArgs.Empty); } if (collision.collider.transform.tag == "Bottom") { OnFailed?.Invoke(this, EventArgs.Empty); } }
private void OnCollisionEnter(Collision other) { GameObject oppObj = other.collider.gameObject; if (oppObj.layer == oppLayer) { collision.bodyPartB = oppObj.GetComponent <BodyPart>(); collision.collision = other; collision.velocity = rb.velocity; OnCollision?.Invoke(collision); } }
private void OnParticleCollision(GameObject other) { int numCollisionEvents = Particle.GetCollisionEvents(other, CollisionEvents); int i = 0; while (i < numCollisionEvents) { OnCollision?.Invoke(other, CollisionEvents[i].intersection); i++; } }
public void CollisionCheck(List <CircleCollider> collidersToCheck) { foreach (var circleCollider in collidersToCheck) { float dist = CalculateDistance(this.Owner.transform.position, circleCollider.Owner.transform.position); if (dist < circleCollider.radius + this.radius) { OnCollisionEvent.Invoke(circleCollider); } } }
public void OnCollisionEnter(Collision collision) { // Only collide with other lava chunks ContactPoint contact = collision.contacts[0]; if (!contact.otherCollider.CompareTag("LavaChunk")) { return; } OnCollision?.Invoke(contact.point, collision.relativeVelocity.magnitude); }
protected bool ManageCollisions() { OnStartCollisionCheck?.Invoke(this); if (!Enabled) { return(EndCollisionCheck(true)); } if (collisionCheckResult != 0) { return(EndCollisionCheck(collisionCheckResult != 1)); } var collisions = CheckCollisions(); if (collisions.Count > 0) { Debug.WriteLine($"{Name} {spellName} collides with n. {collisions.Count}"); } var collides = false; foreach (var collision in collisions) { if (collision.Other.Name == Owner.Name || collision.Other.Name.Contains("spell")) { continue; } if (spellManager.Mask != null && !spellManager.Mask(collision.Other) && !collision.OtherHitBox.StartsWith("wall", StringComparison.Ordinal)) { continue; } Debug.WriteLine($"{Name} {spellName} hits enemy: {collision.Other.Name} ({collision.OtherHitBox})"); collides = true; OnCollision?.Invoke(this, collision); var other = collision.Other as Character; if (other != null && Timer.Get("hitDelayTimer") <= 0) { Owner.DoDamage(this, other, collision); Timer.Set("hitDelayTimer", HitsDelay); break; } if (!Enabled) { break; } if (collisionCheckResult != 0) { return(EndCollisionCheck(collisionCheckResult != 1)); } } return(EndCollisionCheck(collides)); }
public void ResolveCollision(ICollider other) { if (other == this || !other.CollideRectangle.IntersectsWith(CollideRectangle)) { return; } OnTrigger?.Invoke(other); other.InvokeTrigger(this); if (Static || !Collision || !other.Collision) { return; } OnCollision?.Invoke(other); other.InvokeCollision(this); var intersectionType = GetIntersectionType(CollideRectangle, other.CollideRectangle); if ((intersectionType == IntersectionType.Right || intersectionType == IntersectionType.Left) && other.Static) { Velocity.X = 0; } switch (intersectionType) { case IntersectionType.Left: SetX(other.CollideRectangle.Left - CollideRectangle.Width); break; case IntersectionType.Right: SetX(other.CollideRectangle.Right); break; case IntersectionType.Top: SetY(other.CollideRectangle.Top - CollideRectangle.Height + other.Velocity.Y); //Position.Y = other.CollideRectangle.Top - CollideRectangle.Height; if (Velocity.Y > 0) { Velocity.Y = 0; } break; case IntersectionType.Bottom: SetY(other.CollideRectangle.Bottom); if (Velocity.Y < 0) { Velocity.Y = 0; } break; } }