protected virtual void OnCollisionEnter2D(Collision2D p_collision) { GameObject v_otherCollidedObject = p_collision.gameObject; if (v_otherCollidedObject != null && GetComponent <Rigidbody2D>() != null && !RecentCollidedObjects.Contains(v_otherCollidedObject)) { DamageableBlock v_otherBlock = v_otherCollidedObject.GetComponent <DamageableBlock>(); float v_impactForce = GetImpactForce(p_collision.gameObject); float v_attack = v_otherBlock != null?v_otherBlock.Attack *v_otherBlock.GetForceAttenuation() : (v_otherCollidedObject.GetComponent <Rigidbody2D>() == null ? Attack * 1.5f * this.GetForceAttenuation() : 0); float v_attackImpact = v_impactForce * v_attack; float v_damageApplyed = ApplyDamage(v_attackImpact); if (v_damageApplyed > 0) { RecentCollidedObjects.AddChecking(v_otherCollidedObject.gameObject); } if (p_collision.contacts.Length > 0 && v_damageApplyed > MinDamageToShowCollisionEffect) { if (p_collision.contacts.Length > 0) { StartCollisionEffects(p_collision.contacts[0].point); } } _currentTimeToEnableApplyDamage = _currentTimeToEnableApplyDamage <= 0 ? _maxCurrentTimeToEnableApplyDamage : _currentTimeToEnableApplyDamage; //OldVelocity = rigidbody2D != null? rigidbody2D.velocity : Vector2.zero; } }
public virtual void UpdateResistence() { DamageableBlock v_block = GetComponent <DamageableBlock>(); if (v_block != null) { v_block.CurrentLife = v_block.CurrentLife <= 0 ? v_block.MaxLife : Mathf.Clamp(v_block.CurrentLife, 0, v_block.MaxLife); float v_percent = v_block.MaxLife != 0 ? Mathf.Clamp(v_block.CurrentLife / v_block.MaxLife, 0, 1) : 0; v_block.MaxLife = GetArea() * Resistence; v_block.CurrentLife = v_percent * v_block.MaxLife; } }
public Vector2 GetRelativeVelocity(GameObject p_object1, GameObject p_object2) { Vector2 p_velocity1 = Vector2.zero; Vector2 p_velocity2 = Vector2.zero; if (p_object1 != null && p_object2 != null) { DamageableBlock v_block1 = p_object1.GetComponent <DamageableBlock>(); DamageableBlock v_block2 = p_object2.GetComponent <DamageableBlock>(); p_velocity1 = v_block1 != null ? v_block1.OldVelocity : (p_object1.GetComponent <Rigidbody2D>() != null ? p_object1.GetComponent <Rigidbody2D>().velocity : Vector2.zero); p_velocity2 = v_block2 != null ? v_block2.OldVelocity : (p_object2.GetComponent <Rigidbody2D>() != null ? p_object2.GetComponent <Rigidbody2D>().velocity : Vector2.zero); } float v_impactVelocityX = p_velocity1.x - p_velocity2.x; v_impactVelocityX *= Mathf.Sign(v_impactVelocityX); float v_impactVelocityY = p_velocity1.y - p_velocity2.y; v_impactVelocityY *= Mathf.Sign(v_impactVelocityY); return(new Vector2(v_impactVelocityX, v_impactVelocityY)); }
public DamageEventArgs(DamageableBlock p_sender, float p_damage) { m_damage = p_damage; m_sender = p_sender; }