protected virtual void WeaponFire(bool aimAssist) { RaycastHit hit; Ray ray = new Ray(owner.cam.transform.position, owner.cam.transform.forward); if (aimAssist) { ray = AimAssistRayCorrection(ray); } if (Physics.Raycast(ray, out hit, weapon.fireRange, owner.ShootingLayerMask)) { if (weapon.hitEffect != null) { ParticleSystem ps = Instantiate(weapon.hitEffect, hit.point, Quaternion.Euler(hit.normal)).GetComponent <ParticleSystem>(); ps.transform.rotation = Quaternion.LookRotation(hit.normal); } Hitbox hitbox = hit.transform.GetComponent <Hitbox>(); if (hitbox != null) { float damageAfterRange = weapon.GetDamage(Vector3.Distance(transform.position, hit.point)); hitbox.Damage(damageAfterRange, owner.cam.transform.forward * damageAfterRange * 700, owner); } } }
protected override void Update() { base.Update(); if (isAttacking) { RecalculateAttackArea(); Collider2D[] hits = Physics2D.OverlapAreaAll(attackArea.leadingPoing, attackArea.trailingPoint, enemyMask); for (int i = 0; i < hits.Length; i++) { Vector2 heading = hits[i].transform.position - transform.position; RaycastHit2D obstacle = Physics2D.Raycast(transform.position, heading.normalized, heading.magnitude, obstacleMask & ~enemyMask); Hitbox enemyCharacter = hits[i].GetComponent <Hitbox>(); if (!obstacle && !hitTargets.Contains(hits[i])) { enemyCharacter = hits[i].GetComponent <Hitbox>(); if (enemyCharacter != null) { enemyCharacter.Damage(this); hitTargets.Add(hits[i]); } } } } }
public void BulletHit(Packet packet) { bulletMessage = (Message_BulletHit)((PacketSingle)packet).message; Debug.Log("handling bullet hit"); if (bulletMessage.destUID != networkUID) { return; } RaycastHit hitInfo; Vector3 pos = VTMapManager.GlobalToWorldPoint(bulletMessage.pos); Vector3 vel = bulletMessage.dir.toVector3; Vector3 a = pos; a += vel * 100.0f; bool flag = Physics.Linecast(pos, a, out hitInfo, 1025); Hitbox hitbox = null; if (flag) { hitbox = hitInfo.collider.GetComponent <Hitbox>(); if ((bool)hitbox && (bool)hitbox.actor) { Debug.Log("found target bullet hit"); hitbox.Damage(bulletMessage.damage, hitInfo.point, Health.DamageTypes.Impact, hitbox.actor, "lol"); BulletHitManager.instance.CreateBulletHit(hitInfo.point, -vel, true); } } }
public void BulletHit(Packet packet) { bulletMessage = (Message_BulletHit)((PacketSingle)packet).message; Debug.Log("handling bullet hit"); if (bulletMessage.destUID != networkUID) { return; } Vector3 pos = VTMapManager.GlobalToWorldPoint(bulletMessage.pos); Vector3 vel = bulletMessage.dir.toVector3; RaycastHit[] hits; hits = Physics.RaycastAll(pos, vel, 100.0f, 1025); Hitbox hitbox = null; for (int i = 0; i < hits.Length; i++) { RaycastHit hit = hits[i]; hitbox = hit.collider.GetComponent <Hitbox>(); if ((bool)hitbox && (bool)hitbox.actor) { Debug.Log("found target bullet hit"); hitbox.Damage(bulletMessage.damage, hit.point, Health.DamageTypes.Impact, hitbox.actor, "Bullet Hit Network"); BulletHitManager.instance.CreateBulletHit(hit.point, -vel, true); } } }
protected override void WeaponFire(bool aimAssist) { RaycastHit hit; Ray ray = new Ray(owner.cam.transform.position, owner.cam.transform.forward); //Debug //int head = 0; //int torso = 0; //int limbs = 0; if (aimAssist) { ray = AimAssistRayCorrection(ray); } for (int i = 0; i < pellets; i++) { Vector3 direction = Quaternion.AngleAxis(Random.Range(-randomAngle / 2, randomAngle / 2), owner.cam.transform.right) * owner.cam.transform.forward; direction = Quaternion.AngleAxis(Random.Range(-randomAngle / 2, randomAngle / 2), owner.cam.transform.up) * direction; //Debug //Debug.DrawRay(owner.cam.transform.position, direction * weapon.fireRange); if (Physics.Raycast(owner.cam.transform.position, direction, out hit, weapon.fireRange, owner.ShootingLayerMask)) { if (weapon.hitEffect != null) { ParticleSystem ps = Instantiate(weapon.hitEffect, hit.point, Quaternion.Euler(hit.normal)).GetComponent <ParticleSystem>(); ps.transform.rotation = Quaternion.LookRotation(hit.normal); } Hitbox hitbox = hit.transform.GetComponent <Hitbox>(); if (hitbox != null) { // switch (hitbox.bodyPart) // { // case Hitbox.BodyPart.Head: // head++; // break; // case Hitbox.BodyPart.Torso: // torso++; // break; // case Hitbox.BodyPart.Limb: // limbs++; // break; // } float damageAfterRange = weapon.GetDamage(Vector3.Distance(transform.position, hit.point)) / pellets; //Ska jag dividera med antalet pellets? Blir enklare att räkna om jag kan göra så. hitbox.Damage(damageAfterRange, owner.cam.transform.forward * damageAfterRange * 700, owner); } } } //Debug.Log("Head: " + head + " | Torso: " + torso + " | Limbs: " + limbs + " | Missed: " + (pellets - head-torso-limbs)); }
// Update is called once per frame void Update() { if (freezeController.getFreeze()) { return; } Collider2D[] results = new Collider2D[5]; ContactFilter2D filter = new ContactFilter2D(); filter.SetLayerMask(collisionMask); ctrlCollider.OverlapCollider(filter, results); for (int i = 0; i < results.Length; i++) { Collider2D hit = results[i]; if (!hit) { continue; } Hitbox hitbox = hit.GetComponent <Hitbox>(); if (!hitbox) { continue; } if (instakill) { hitbox.Die(); } else { Controller2D ctrl = hitbox.GetComponent <Controller2D>(); Vector2 direction = ctrl == null ? Vector2.right : -ctrl.collisions.faceDir * Vector2.right; if (ctrl.transform.position.y < transform.position.y) { direction.y = -1; } hitbox.Damage(damage.GetValue(), new Hitbox.Knockback { duration = knockbackDuration.GetValue(), direction = direction, speed = knockbackSpeed.GetValue() }); } } }
void CheckCollisions(ref Projectile proj) { ContactFilter2D filter = new ContactFilter2D(); filter.layerMask = hitMask | obstacleMask; Collider2D[] hits = new Collider2D[5]; proj.collider.OverlapCollider(filter, hits); List <Hitbox> hitTargets = new List <Hitbox>(hits.Length); for (int j = 0; j < hits.Length; j++) { if (hits[j] == null) { continue; } Destroy(proj.collider.gameObject); proj.destroyed = true; if (hitMask == (hitMask | 1 << hits[j].gameObject.layer)) { Hitbox hitbox = hits[j].GetComponent <Hitbox>(); if (!hitbox) { continue; } if (hitTargets.Contains(hitbox)) { continue; } if (instakill) { hitbox.Die(); } else { hitbox.Damage(damage.GetValue(), new Hitbox.Knockback { duration = knockbackDuration.GetValue(), direction = projectileDirection.x != 0 ? new Vector2(Mathf.Sign(projectileDirection.x), 0) : Vector2.zero, speed = knockbackSpeed.GetValue() }); } } } }
protected virtual void HandleAttackOnTouch() { if (attackOnTouch <= 0) { return; } if (navigator.GetKnockbackStatus()) { return; } Collider2D[] hits = new Collider2D[5]; List <Collider2D> processedHits = new List <Collider2D>(); ctrlCollider.OverlapCollider(contact, hits); for (int i = 0; i < hits.Length; i++) { if (processedHits.Contains(hits[i]) || hits[i] == null) { continue; } if (agent != null && agent.GetHitTargets() != null && agent.GetHitTargets().Contains(hits[i])) { continue; } processedHits.Add(hits[i]); Hitbox hitbox = hits[i].GetComponent <Hitbox>(); if (hitbox == null) { continue; } hitbox.Damage(attackOnTouch, new Hitbox.Knockback { direction = hitbox.transform.position - transform.position, duration = knockbackOnTouch, speed = knockbackSpeedOnTouch }); } }
void DetectHit() { ContactFilter2D filter = new ContactFilter2D(); filter.layerMask = hitMask; Collider2D[] hits = new Collider2D[5]; head.OverlapCollider(filter, hits); List <Hitbox> hitTargets = new List <Hitbox>(hits.Length); for (int i = 0; i < hits.Length; i++) { if (hits[i] == null) { continue; } Hitbox hitbox = hits[i].GetComponent <Hitbox>(); if (!hitbox) { continue; } if (hitTargets.Contains(hitbox)) { continue; } if (instakill) { hitbox.Die(); } else { hitbox.Damage(damage.GetValue(), new Hitbox.Knockback { duration = knockbackDuration.GetValue(), direction = rb2d.angularVelocity > 0 ? Vector2.right : -Vector2.right, speed = knockbackSpeed.GetValue() }); } } }
public void BulletHit(Packet packet) { bulletMessage = (Message_BulletHit)((PacketSingle)packet).message; Debug.Log("handling bullet hit"); if (bulletMessage.destUID != networkUID) { return; } RaycastHit hitInfo; Vector3 pos = VTMapManager.GlobalToWorldPoint(bulletMessage.pos); Vector3 vel = bulletMessage.dir.toVector3; Vector3 a = pos; a += vel * 100.0f; bool flag = Physics.Linecast(pos, a, out hitInfo, 1025); Actor source = null; if (AIDictionaries.allActors.ContainsKey(bulletMessage.sourceActorUID)) { source = AIDictionaries.allActors[bulletMessage.sourceActorUID]; } Hitbox hitbox = null; if (flag) { hitbox = hitInfo.collider.GetComponent <Hitbox>(); if ((bool)hitbox && (bool)hitbox.actor) { Debug.Log("found target bullet hit"); hitbox.Damage(bulletMessage.damage * 3.0f, hitInfo.point, Health.DamageTypes.Impact, source, "Bullet Impact"); BulletHitManager.instance.CreateBulletHit(hitInfo.point, -vel, true); } } else { health.Damage(bulletMessage.damage * 3.0f, ownerActor.gameObject.transform.position, Health.DamageTypes.Impact, source, "Bullet Impact"); BulletHitManager.instance.CreateBulletHit(ownerActor.gameObject.transform.position, -vel, true); } }
private void OnCollisionEnter2D(Collision2D collision) { if (!entity.IsOwner()) { return; } var deathEvent = DeathEvent.Create(entity); deathEvent.Send(); BoltNetwork.Destroy(gameObject); Hitbox otherHitbox = collision.collider.GetComponent <Hitbox>(); if (otherHitbox) { otherHitbox.Damage(damage); } }
private void Shoot() { RaycastHit hit; muzzleFlare.Play(true); ResetShootTimers(); if (Physics.Raycast(PlayerController.Camera.transform.position, PlayerController.Camera.transform.forward, out hit, fireRange)) { ParticleSystem ps = Instantiate(hitEffect, hit.point, Quaternion.Euler(hit.normal)).GetComponent <ParticleSystem>(); ps.transform.rotation = Quaternion.LookRotation(hit.normal); Hitbox hitbox = hit.transform.GetComponent <Hitbox>(); if (hitbox != null) { hitbox.Damage(damage, PlayerController.Camera.transform.forward * damage * 700); } } PlayerController.ShootCallback(recoilAmmount); }
// Update is called once per frame void Update() { float moveDistance = Vector2.Distance(attackAgent.transform.position, transform.position); if (moveDistance >= attackAgent.range) { Destroy(gameObject); return; } if (attackAgent.trackType == ShooterAttackAgent.TrackType.Track && trackDurationLeft > 0) { trackDurationLeft -= Time.deltaTime; velocity = attackAgent.bulletSpeed * (attackAgent.target.position - attackAgent.transform.position).normalized; } Vector2 moveAmount = velocity * Time.deltaTime; transform.Translate(moveAmount); UpdateRaycastOrigins(); RaycastHit2D hit = Physics2D.Raycast(raycastOrigins.center, moveAmount.normalized, moveAmount.magnitude, compoundMask); Debug.DrawRay(raycastOrigins.center, moveAmount, Color.red); if (hit) { if (attackAgent.enemyMask == (attackAgent.enemyMask | 1 << hit.collider.gameObject.layer)) { Hitbox hitbox = hit.collider.GetComponent <Hitbox>(); if (hitbox) { hitbox.Damage(attackAgent); } } Destroy(gameObject); } }
protected override void Update() { base.Update(); if (isAttacking) { controller.Move(chargeVelocity * Time.deltaTime, navDirection); Collider2D[] hits = new Collider2D[5]; controller.ctrlCollider.OverlapCollider(contact, hits); for (int i = 0; i < hits.Length; i++) { if (hitTargets.Contains(hits[i]) || hits[i] == null) { continue; } hitTargets.Add(hits[i]); Hitbox hitbox = hits[i].GetComponent <Hitbox>(); if (hitbox == null) { continue; } hitbox.Damage(attack, new Hitbox.Knockback { direction = hitbox.transform.position - transform.position, duration = knockback, speed = knockbackSpeed }); chargeVelocity = Vector2.zero; } } }
// Update is called once per frame void Update() { if (freezeController.getFreeze()) { return; } Vector3 heading = transform.position - initialPosition; UpdateRaycastOrigins(); if (!retracting) { moveAmount.x = directionX * squashSpeed * Time.deltaTime; moveAmount.y = directionY * squashSpeed * Time.deltaTime; if (heading.magnitude >= squashRange) { retracting = true; } } else { moveAmount.x = -directionX * retractSpeed * Time.deltaTime; moveAmount.y = -directionY * retractSpeed * Time.deltaTime; Vector3 retractingHeading = initialPosition - initialPosition + new Vector3(directionX, directionY); if (heading.normalized != retractingHeading.normalized) { retracting = false; } } if (moveAmount.y != 0) { float dirY = Mathf.Sign(moveAmount.y); float rayLength = moveAmount.y; for (int i = 0; i < verticalRayCount; i++) { Vector2 rayOrigin = (dirY > 0 ? raycastOrigins.topLeft : raycastOrigins.bottomLeft) + Vector2.right * (verticalRaySpacing * i); RaycastHit2D hit = Physics2D.Raycast(rayOrigin, dirY * Vector2.up, rayLength, collisionMask); Debug.DrawRay(rayOrigin, dirY * Vector2.up * rayLength, Color.red); if (hit) { Controller2D hitCtrl = hit.collider.GetComponent <Controller2D>(); if (hitCtrl) { hit.collider.GetComponent <Controller2D>().Move(moveAmount, false); } if (squashRange - heading.magnitude <= hit.collider.bounds.size.y + damageRangeAroundTarget) { //Actually hit at the peak of the squash distance Hitbox hitbox = hit.collider.GetComponent <Hitbox>(); if (hitbox) { if (instakill) { hitbox.Die(); } else { hitbox.Damage(damage.GetValue(), new Hitbox.Knockback()); } } retracting = !retracting; moveAmount.y = moveAmount.y - dirY * (hit.distance - skinWidth); } break; } } } if (moveAmount.x != 0) { float dirX = Mathf.Sign(moveAmount.x); float rayLength = moveAmount.x; for (int i = 0; i < horizontalRayCount; i++) { Vector2 rayOrigin = (dirX < 0 ? raycastOrigins.bottomLeft : raycastOrigins.bottomRight) + Vector2.up * (horizontalRaySpacing * i); RaycastHit2D hit = Physics2D.Raycast(rayOrigin, dirX * Vector3.right, rayLength, collisionMask); Debug.DrawRay(rayOrigin, dirX * Vector3.right * rayLength, Color.red); if (hit) { Controller2D hitCtrl = hit.collider.GetComponent <Controller2D>(); if (hitCtrl) { hit.collider.GetComponent <Controller2D>().Move(moveAmount, false); } if (squashRange - heading.magnitude <= hit.collider.bounds.size.x + damageRangeAroundTarget) { //Actually hit at the peak of the squash distance Hitbox hitbox = hit.collider.GetComponent <Hitbox>(); if (hitbox) { if (instakill) { hitbox.Die(); } else { hitbox.Damage(damage.GetValue(), new Hitbox.Knockback()); } } retracting = !retracting; moveAmount.x = moveAmount.x - dirX * (hit.distance - skinWidth); } break; } } } transform.Translate(moveAmount); }
protected int GetDamage(Hitbox hitbox) { Rigidbody2D hitRB = hitbox.GetComponent <Rigidbody2D>(); return(hitbox.Damage(hitRB == null ? 0 : (int)hitRB.velocity.sqrMagnitude)); }