private void OnTriggerEnter2D(Collider2D collider) { Hitbox hitbox = collider.GetComponent <Hitbox>(); Hurtbox hurtbox = collider.GetComponent <Hurtbox>(); if (hitbox != null) { //if (hitbox.associatedCharacterStats == null) //{ // Debug.LogError(hitbox.name + ": Hitbox missing an associated character stats reference"); // return; //} if (hitbox.associatedCharacterStats.hitboxLayer == this.associatedCharacterStats.hitboxLayer) { return; } onHitboxEnteredEvent.Invoke(hitbox); return; } if (hurtbox != null) { //if (hurtbox.associatedCharacterStats == null) //{ // Debug.LogError(hurtbox.name + ": Hurtbox missing associated character stats reference"); // return; //} if (hurtbox.associatedCharacterStats.hitboxLayer == this.associatedCharacterStats.hitboxLayer) { return; } onHurtboxEnteredEvent.Invoke(hurtbox); return; } }
/// <summary> /// Sets off the appropritate triggers when our hitboxes enter a hitbox, hurtbox or generic collider2D /// </summary> /// <param name="collider"></param> protected virtual void OnTriggerEnter2D(Collider2D collider) { Hitbox hitbox = collider.GetComponent <Hitbox>(); Hurtbox hurtbox = collider.GetComponent <Hurtbox>(); if (hitbox != null) { //if (hitbox.associatedCharacterStats == null) //{ // Debug.LogError(hitbox.name + " contains a null associated CharacterStats reference"); // return; //} if (hitbox.associatedCharacterStats.hitboxLayer == this.associatedCharacterStats.hitboxLayer) { return; } onHitboxEnteredEvent.Invoke(hitbox); return; } if (hurtbox != null) { //if (hurtbox.associatedCharacterStats == null) //{ // Debug.LogError(hurtbox.name + " contains a null associated CharacterStats reference"); // return; //} if (hurtbox.associatedCharacterStats.hitboxLayer == this.associatedCharacterStats.hitboxLayer) { return; } onHurtboxEnteredEvent.Invoke(hurtbox); return; } onCollisionEvent.Invoke(collider); }
public void collidedWith(Collider2D collider) { //if (gameObject.GetComponent<Rigidbody>().velocity.x > 0) //if we are throwing to the right //{ // //The x-extents of our player's collider is 0.62, so we subtract one more than that to ensure the collider will not overlap with the obstacle // transform.position = new Vector3(collider.bounds.min.x - 0.63f, transform.position.y, transform.position.z); //} //else //{ // //The x-extents of our player's collider is 0.62, so we subtract one more than that to ensure the collider will not overlap with the obstacle // transform.position = new Vector3(collider.bounds.max.x + 0.63f, transform.position.y, transform.position.z); //} spawningAttack.SetCollider(collider); spawningAttack.collided = true; if (batonOnHitClip != null) { playerAudioSource.volume = SoundManager.Instance.PlayerBatonOnHitVolume; SoundManager.Instance.PlayWithRandomizedPitch(playerAudioSource, batonOnHitClip); } if (collider.tag != "Obstacle") { Hurtbox hurtbox = collider.GetComponent <Hurtbox>(); hurtbox.ApplyAttack(damage); } }
private void OnTriggerEnter(Collider other) { //Wall Collision if (other.gameObject.layer == 8 && activeBox) { Explode(); } //Entity Collision bool hit = false; if (other.gameObject.tag == "Hurtbox" && activeBox) { int hurtboxID = other.gameObject.GetInstanceID(); if (!BoxesHit.Contains(hurtboxID)) { Hurtbox hb = other.GetComponent <Hurtbox>(); if (hitID != hb.hitID) { BoxesHit.Add(hurtboxID); hit = hb.Damage(attackType, damage, knockback, weightClass, direction, ownerStatus); } } if (hit) { Explode(); } } //Breakable Collision if (other.gameObject.tag == "Neutral") { //Damage Entity (Break the thing) } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (treeView1.SelectedNode.Index > -1) { Runtime.ParamManager.UnselectHurtboxes(); hurtboxData = new DataTable(); dataGridView1.DataSource = hurtboxData; Hurtbox hurtbox = Runtime.ParamManager.Hurtboxes[treeView1.SelectedNode.Index]; hurtboxData.Columns.Add(new DataColumn("Name") { ReadOnly = true }); hurtboxData.Columns.Add("Value"); hurtboxData.Rows.Add("Bone", hurtbox.Bone); hurtboxData.Rows.Add("Size", hurtbox.Size); hurtboxData.Rows.Add("X Pos", hurtbox.X); hurtboxData.Rows.Add("Y Pos", hurtbox.Y); hurtboxData.Rows.Add("Z Pos", hurtbox.Z); hurtboxData.Rows.Add("X Stretch", hurtbox.X2); hurtboxData.Rows.Add("Y Stretch", hurtbox.Y2); hurtboxData.Rows.Add("Z Stretch", hurtbox.Z2); hurtboxData.Rows.Add("Zone", hurtbox.Zone == Hurtbox.LW_ZONE ? "Low" : hurtbox.Zone == Hurtbox.HI_ZONE ? "High" : "Mid"); Runtime.SelectedHurtboxID = hurtbox.ID; } }
public void collisionedWith(Collider2D collider) { Hurtbox hurtbox = collider.GetComponent <Hurtbox>(); hurtbox.StateHit(); hurtbox?.getHitBy(damage, stunTime); }
public void CollidedWith(Collider2D collider) { Hurtbox hurtbox = collider.GetComponent <Hurtbox>(); if (hurtbox) { if ((hurtbox.parentResponder.GetType() == typeof(Character))) { if ((Character)hurtbox.parentResponder == parentChar)//do not hit yourself { return; } } foreach (IGotHitResponder o in ObjectsHit) { if (o == hurtbox.parentResponder)//can not hit the same object multiple times with the same hitbox { return; } } hurtbox.GotHit(this); ObjectsHit.Add(hurtbox.parentResponder); parentChar.charState.OnDealDamage(hitboxData.damage); StartCoroutine(ApplyHitlag(FormulaHelper.GetFramesOfHitLag(hitboxData))); } }
public void collisionedWith(Collider collider) { Hurtbox hurtbox = collider.GetComponent <Hurtbox>(); if (hurtbox != null) { if (hurtbox.isPlayer != hitbox.isPlayer) { //Vector3 kb_vec = new Vector3(0, 0, 0); Vector3 kb_vec = transform.parent.forward * kb; hurtbox.damaged(damage, kb_vec, transform.parent); if (hitbox.isPlayer && hurtbox.hp >= 0) { PlayerPrefs.SetInt("Score", PlayerPrefs.GetInt("Score") + ((int)damage * 10)); } else if (!hitbox.isPlayer && hurtbox.hp + damage > 0) { if (PlayerPrefs.GetInt("Score") - ((int)damage * 10) <= 0) { PlayerPrefs.SetInt("Score", 0); } else { PlayerPrefs.SetInt("Score", PlayerPrefs.GetInt("Score") - ((int)damage * 10)); } } } } }
public void OnTriggerEnter2D(Collider2D other) { Hurtbox otherHurtbox = other.GetComponent <Hurtbox>(); if (other.isTrigger && otherHurtbox != null && otherHurtbox.IsActive() && objectMessenger != null) { objectMessenger.Invoke(Message.HIT_OTHER, new object[] { boxType }); IMessenger otherObjectMessenger = other.GetComponent <IMessenger> (); if (otherObjectMessenger == null) { otherObjectMessenger = other.GetComponentInParent <IMessenger> (); } if (otherObjectMessenger == null) { otherObjectMessenger = other.GetComponentInChildren <IMessenger> (); } if (otherObjectMessenger != null) { //We choose an arbitrarily large value for damage //so that it is guaranteed to kill the object. int damage = (instantKill ? 1000 : 1); otherObjectMessenger.Invoke(Message.HIT_OTHER, new object[] { boxType, damage }); } } }
/// <summary> /// Copy data from current action and convert relative box position with fighter position /// </summary> private void ApplyCurrentActionData() { Hitboxes.Clear(); Hurtboxes.Clear(); foreach (HitboxData hitbox in fighterData.Actions[CurrentActionID].GetHitboxData(CurrentActionFrame)) { Hitbox box = new Hitbox { Rect = TransformToFightRect(hitbox.rect, Position, IsFaceRight), Proximity = hitbox.proximity, AttackID = hitbox.attackID }; Hitboxes.Add(box); } foreach (HurtboxData hurtbox in fighterData.Actions[CurrentActionID].GetHurtboxData(CurrentActionFrame)) { Hurtbox box = new Hurtbox(); Rect rect = hurtbox.useBaseRect ? fighterData.baseHurtBoxRect : hurtbox.rect; box.Rect = TransformToFightRect(rect, Position, IsFaceRight); Hurtboxes.Add(box); } PushboxData pushBoxData = fighterData.Actions[CurrentActionID].GetPushboxData(CurrentActionFrame); if (pushBoxData != null) { Pushbox = new Pushbox(); Rect pushRect = pushBoxData.useBaseRect ? fighterData.basePushBoxRect : pushBoxData.rect; Pushbox.Rect = TransformToFightRect(pushRect, Position, IsFaceRight); } }
public override void HitCheck() { List <Collider> hurtboxes = new List <Collider>(); LayerMask hurtboxMask = LayerMask.GetMask("Hurtbox"); hitCircles.Add(new SphereHitbox(Adjust() + (direction * (0.2f + offset)), 0.4f)); for (int h = 0; h < hitCircles.Count; h++) { hurtboxes.AddRange(Physics.OverlapSphere(hitCircles[h].position, hitCircles[h].radius, hurtboxMask)); } for (int i = 0; i < hurtboxes.Count; i++) { int hurtboxID = hurtboxes[i].gameObject.GetInstanceID(); if (BoxesHit.Contains(hurtboxID)) { continue; } else { Hurtbox hb = hurtboxes[i].GetComponent <Hurtbox>(); if (hitID != hb.hitID) { BoxesHit.Add(hurtboxID); Vector3 dir = direction; if (attackStep == 9) { dir = hurtboxes[i].transform.position - transform.position; } hb.Damage(attackType, damage, knockback, weightClass, dir, ownerStatus); } } } }
//OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { rb = GameObject.Find("BossSpiderBook").GetComponent <Rigidbody2D>(); // gets rigidbody2d of BossSpiderBook since code is in BossGraphics shoot = GameObject.Find("BossSpiderBook"); heart = GameObject.Find("Heart"); heart.GetComponent <CircleCollider2D>().enabled = true; // enable heart collider for vulnerable state vulnerableCollider = GameObject.Find("VulnerableCollider").GetComponent <PolygonCollider2D>(); vulnerableCollider.enabled = true; // enable body collider for vulnerable state invulnerableCollider = GameObject.Find("InvulnerableCollider").GetComponent <PolygonCollider2D>(); invulnerableCollider.enabled = false; // disable colliders for invulnerable state hurtbox = (Hurtbox)heart.GetComponent(typeof(Hurtbox)); hurtbox.isHurt = false; leftDistance = new Vector2(-5.85f, rb.position.y); // max distance boss can move to the left rightDistance = new Vector2(5.85f, rb.position.y); // max distance boss can move to the right resetPosition = new Vector2(rb.position.x, rb.position.y); reachedLeft = false; attackSet = 4; }
private void FireRaycast() { Ray ray = new Ray(firePoint.position, firePoint.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, raycastProjectileLayerMask)) { int hitLayer = hit.collider.gameObject.layer; //player hit enemy hurtbox or enemy hit player hurtbox if ((isPlayer && hitLayer == layerInfo.enemyHurtbox) || (!isPlayer && hitLayer == layerInfo.playerHurtbox)) { Hurtbox hurtbox = hit.collider.gameObject.GetComponent <Hurtbox>(); hurtbox.SendDamage(damage); } //spawn hitsparks Vector3 inDir = firePoint.position - hit.point; Vector3 dir = Vector3.Reflect(inDir, hit.normal); dir *= -1; // Debug.DrawRay(hit.point, inDir, Color.red, 1f); // Debug.DrawRay(hit.point, hit.normal, Color.green, 1f); // Debug.DrawRay(hit.point, dir, Color.blue, 1f); Quaternion newRot = Quaternion.LookRotation(dir); GameObject hitSparks = raycastProjectileInfo.hitSparks.GetPooledObject(hit.point, newRot); //play audio on impact point } }
public void AddHurtbox(Hurtbox hurtbox) { if (!hurtboxes.Contains(hurtbox)) { hurtboxes.Add(hurtbox); } }
// Update is called once per frame public void StepFrame() { if (active) { Collider[] cols = Physics.OverlapBox(col.bounds.center, col.bounds.extents, col.transform.rotation, LayerMask.GetMask("Hurtbox")); foreach (Collider c in cols) { Hurtbox hurt = c.GetComponent <Hurtbox>(); //Ignore hurtboxes and hitboxes from the same source if (hurt.owner != owner) { c.SendMessage("onHit", this); } } if (_life > 0) { _life--; } if (_life == 0) { Deactivate(); } } }
public override void _Ready() { GD.Randomize(); stats = GetNode <Stats>("Stats"); stats.OnZeroHealth += Death; hurtbox = GetNode <Hurtbox>("Hurtbox"); hurtbox.OnInvincibilityEnded += BlinkStop; hurtbox.OnInvincibilityStarted += BlinkStart; playerZone = GetNode <PlayerDetection>("PlayerDetection"); batSprite = GetNode <AnimatedSprite>("AnimatedSprite"); softCollision = GetNode <SoftCollision>("SoftCollision"); wanderController = GetNode <WanderController>("WanderController"); rng = new RandomNumberGenerator(); stateArray = new List <AIState> { AIState.IDLE, AIState.WANDER }; state = PickRandomState(stateArray); animPlayer = GetNode <AnimationPlayer>("AnimationPlayer"); }
public virtual void Damage(Hurtbox hurt, Hitbox hit) { if (hit.gameObject.tag != gameObject.tag && !_isInvincible) { health -= hit.damage; if (hit.direction == Vector3.zero) { Force(hurt.transform.position - hit.transform.position, hit.force); } else { Force(hit.direction, hit.force); } _sprite.FlashAdd(Color.white); _sprite.Shake(10, 0.125f); Particle.SpawnCross(transform.position + new Vector3(Random.Range(-0.25f, 0.25f), Random.Range(-0.25f, 0.25f), 0), Color.red); Particle.SpawnCross(transform.position + new Vector3(Random.Range(-0.25f, 0.25f), Random.Range(-0.25f, 0.25f), 0), Color.blue); Particle.SpawnCross(transform.position + new Vector3(Random.Range(-0.25f, 0.25f), Random.Range(-0.25f, 0.25f), 0), Color.green); SoundEffects.PlayHit(); DamagePlus(); hit.OnHit(); } }
private void ProjectileHit(Hurtbox _hurtbox, Projectile _projectile) { if (_hurtbox.m_damageType == EDamageType.wormholePoint) { if (m_pointGameObjects[m_pointsIndex].GetInstanceID() == _hurtbox.gameObject.GetInstanceID()) { ++m_pointsIndex; if (m_pointsIndex >= m_points.Count) { // Attack finished AttackFinished(); } else { MoveTowardsCurrentPoint(); } } } else if (_hurtbox.m_damageType == EDamageType.player) { _hurtbox.ApplyDamage(_projectile.m_damage); AttackFinished(); } }
public void CollidedWith(Collider _collider) { Parryable parryable = _collider.GetComponent <Parryable>(); if (parryable) { parryable.OnParried(); AudioManager.Instance.PlaySound("parry"); EffectsManager.SpawnEffect("Parry", _collider.transform.position, Quaternion.Euler(-90.0f, 0.0f, 0.0f), Vector3.one, 2.0f); m_parriedSomething = true; m_player.CurrentCombo += 1; m_mana.Mana += parryable.m_manaValue * m_player.m_comboMultiplier; } Hurtbox hurtbox = _collider.GetComponent <Hurtbox>(); if (hurtbox) { if (hurtbox.m_damageType != m_hitbox.m_damageType) { hurtbox.ApplyDamage(m_damage); } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); Hurtbox hitbox = (Hurtbox)target; hitbox.gameObject.layer = EditorGUILayout.LayerField(hitbox.gameObject.layer, options); }
/// <summary> /// Copy data from current action and convert relative box position with fighter position /// </summary> private void ApplyCurrentActionData() { hitboxes.Clear(); hurtboxes.Clear(); foreach (var hitbox in fighterData.actions[currentActionID].GetHitboxData(currentActionFrame)) { var box = new Hitbox(); box.rect = TransformToFightRect(hitbox.rect, position, isFaceRight); box.proximity = hitbox.proximity; box.attackID = hitbox.attackID; hitboxes.Add(box); } foreach (var hurtbox in fighterData.actions[currentActionID].GetHurtboxData(currentActionFrame)) { var box = new Hurtbox(); Rect rect = hurtbox.useBaseRect ? fighterData.baseHurtBoxRect : hurtbox.rect; box.rect = TransformToFightRect(rect, position, isFaceRight); hurtboxes.Add(box); } var pushBoxData = fighterData.actions[currentActionID].GetPushboxData(currentActionFrame); pushbox = new Pushbox(); Rect pushRect = pushBoxData.useBaseRect ? fighterData.basePushBoxRect : pushBoxData.rect; pushbox.rect = TransformToFightRect(pushRect, position, isFaceRight); }
public void RemoveHurtbox(Hurtbox hurtbox) { if (hurtboxes.Contains(hurtbox)) { hurtboxes.Remove(hurtbox); } }
// Update is called once per frame protected override void PostUpdate() { //the time is ticking if the hitbox is active if (timer.TickTimer()) { //query collisions if the hitbox is supposed to be active boxCollider.OverlapCollider(filter, curColliding); diffColliders = curColliding.Except(wasColliding).ToList(); wasColliding = curColliding.ToList(); int len = diffColliders.Count; if (len > 0) { for (int i = 0; i < len; i++) { Hurtbox box = curColliding[i].GetComponent <Hurtbox>(); if (box.GetAllignment() != allignment) { box.GetHit(); player.OnHit(data); } } } } }
private void Start() { health = GetComponent <Health>(); health.SetHealth(1); health.OnDeath += (x, y) => Kill(); Hurtbox.Create(gameObject, health); }
public override void HitCheck() { List <Collider> hurtboxes = new List <Collider>(); LayerMask hurtboxMask = LayerMask.GetMask("Hurtbox"); switch (attackStep) { case 1: hitCircles.Add(new SphereHitbox(Adjust() + (direction * (0.2f + offset)), 0.4f)); break; case 2: hitCircles.Add(new SphereHitbox(Adjust() + (direction * (0.2f + offset)), 0.4f)); break; case 3: hitCircles.Add(new SphereHitbox(Adjust() + (direction * (0.2f + offset)), 0.45f)); Vector3 newDir = (Quaternion.AngleAxis(40, Vector3.forward) * direction); hitCircles.Add(new SphereHitbox(Adjust() + (newDir * (0.2f + offset)), 0.35f)); newDir = (Quaternion.AngleAxis(-40, Vector3.forward) * direction); hitCircles.Add(new SphereHitbox(Adjust() + (newDir * (0.2f + offset)), 0.35f)); break; case 4: hitCircles.Add(new SphereHitbox(Adjust() + (direction * (0.32f + offset)), 0.35f)); hitCircles.Add(new SphereHitbox(Adjust() + (direction * (0.8f + offset)), 0.35f)); break; case 5: hitCircles.Add(new SphereHitbox(Adjust() + (direction * (0.5f + offset)), 0.57f)); hitCircles.Add(new SphereHitbox(Adjust() + (direction * (0.1f + offset)), 0.57f)); break; } for (int h = 0; h < hitCircles.Count; h++) { hurtboxes.AddRange(Physics.OverlapSphere(hitCircles[h].position, hitCircles[h].radius, hurtboxMask)); } for (int i = 0; i < hurtboxes.Count; i++) { int hurtboxID = hurtboxes[i].gameObject.GetInstanceID(); if (BoxesHit.Contains(hurtboxID)) { continue; } else { Hurtbox hb = hurtboxes[i].GetComponent <Hurtbox>(); if (hitID != hb.hitID) { BoxesHit.Add(hurtboxID); Vector3 dir = direction; hb.Damage(attackType, damage, knockback, weightClass, dir, ownerStatus); } } } }
private void ProjectileHitPlayer(Hurtbox _player, Projectile _projectile) { Destroy(_projectile.gameObject); _player.ApplyDamage(_projectile.m_damage); //HealthComponent healthComp = _player.GetComponent<HealthComponent>(); //healthComp.Health -= _projectile.m_damage; }
private void Awake() { _lineRenderer = GetComponent <LineRenderer>(); //The hurtbox of this object isn't used normally (with collision) but is applied by the laser programmatically _hurtbox = GetComponent <Hurtbox>(); _laserAudio = Commons.AudioManager.GetComponent <LaserAudio>(); }
public void CollidedWith(Collider collider) { Debug.Log("Player collided with " + collider.gameObject.name); Hurtbox hurtbox = collider.GetComponent <Hurtbox>(); IHealthController hurtBoxController = hurtbox.GetComponentInParent <IHealthController>(); // the parent gameobject will implement the health and damage Damage attackDamage = new Damage(15); hurtBoxController?.ReceiveDamage(attackDamage); }
/// <summary> /// /// </summary> /// <param name="hurtbox"></param> public void HitEnemy(Hurtbox hurtbox) { if (hurtbox.associatedCharacterStats == null) { return; } hurtbox.associatedCharacterStats.TakeDamage(damageToDeal); Destroy(this.gameObject); }
private void OnTriggerEnter(Collider other) { Hurtbox hurtBox = other.GetComponent <Hurtbox>(); if (hurtBox != null) { hurtBox.Hit(_hitData); } }