Skip to content
Snippets Groups Projects
Verified Commit 8ba306b1 authored by Adrian Paschkowski's avatar Adrian Paschkowski :thinking:
Browse files

Allow dead bodies to hit the ground

Use physics layers instead of disabling physics; otherwise dead bodies might float in the sky if the Fighter was standing on top of another one.
parent de0d0118
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback ...@@ -26,6 +26,7 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback
protected new Rigidbody2D rigidbody; protected new Rigidbody2D rigidbody;
protected new BoxCollider2D collider; protected new BoxCollider2D collider;
protected SpriteRenderer spriteRenderer; protected SpriteRenderer spriteRenderer;
protected HealthBarController healthBarController;
protected bool alive { get => currentHealth > 0; } protected bool alive { get => currentHealth > 0; }
protected bool roundRunning = false; protected bool roundRunning = false;
protected FighterTypes fighterType; protected FighterTypes fighterType;
...@@ -33,8 +34,8 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback ...@@ -33,8 +34,8 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback
protected Vector3 initalScale; protected Vector3 initalScale;
protected Vector3 initalPosition; protected Vector3 initalPosition;
protected int initialLayer;
protected Sprite initialSprite; protected Sprite initialSprite;
protected HealthBarController healthBarController;
protected abstract bool CanAttack(); protected abstract bool CanAttack();
protected abstract void Attack(); protected abstract void Attack();
...@@ -50,9 +51,10 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback ...@@ -50,9 +51,10 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback
healthBarController = GetComponentInChildren<HealthBarController>(); healthBarController = GetComponentInChildren<HealthBarController>();
fighterType = FighterTypes.ENEMY; fighterType = FighterTypes.ENEMY;
initalPosition = transform.position; initalPosition = transform.position;
initalScale = transform.localScale; initalScale = transform.localScale;
initialLayer = gameObject.layer;
initialSprite = spriteRenderer.sprite; initialSprite = spriteRenderer.sprite;
} }
...@@ -101,10 +103,8 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback ...@@ -101,10 +103,8 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback
{ {
animator.SetTrigger("Death"); animator.SetTrigger("Death");
callbacks.ForEach(c => c.OnFighterDeath(this)); callbacks.ForEach(c => c.OnFighterDeath(this));
// Disable own collider so that other Fighters can run over our dead body // Disable own collision so that other Fighters can run over our dead body
collider.enabled = false; gameObject.layer = LayerMask.NameToLayer("Ground-Only Collision");
// Let's not fall through the world, without any active colliders
rigidbody.bodyType = RigidbodyType2D.Static;
healthBarController.SetHealthBarEnabled(false); healthBarController.SetHealthBarEnabled(false);
} }
else else
...@@ -152,6 +152,7 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback ...@@ -152,6 +152,7 @@ public abstract class Fighter : MonoBehaviour, IRoundCallback
rigidbody.velocity = Vector2.zero; rigidbody.velocity = Vector2.zero;
rigidbody.MovePosition(initalPosition); rigidbody.MovePosition(initalPosition);
transform.localScale = initalScale; transform.localScale = initalScale;
gameObject.layer = initialLayer;
spriteRenderer.sprite = initialSprite; spriteRenderer.sprite = initialSprite;
callbacks.Clear(); callbacks.Clear();
healthBarController.SetHealthBarEnabled(false); healthBarController.SetHealthBarEnabled(false);
......
...@@ -53,4 +53,4 @@ Physics2DSettings: ...@@ -53,4 +53,4 @@ Physics2DSettings:
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: fffbeffffffbeffffffbeffffffffffffffbeffffffbeffffffffffffffffffffffdfffffffeefffc8ffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8f9ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff m_LayerCollisionMatrix: fffbeffffffaeffffffaeffffffffffffffaeffffffaefffffffffffffffffffc9f8effffffeefffc8feefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8f8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
...@@ -17,7 +17,7 @@ TagManager: ...@@ -17,7 +17,7 @@ TagManager:
- UI - UI
- -
- -
- Ground Sensor - Ground-Only Collision
- Fighter - Fighter
- Weapon - Weapon
- -
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment