Skip to content

Commit ded4a20

Browse files
committed
Turn off collisions for 3 seconds after respawning
1 parent 7f1f7bc commit ded4a20

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Assets/Scripts/Player.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ private void Awake()
4949
_rigidbody = GetComponent<Rigidbody2D>();
5050
}
5151

52+
private void OnEnable()
53+
{
54+
// Turn off collisions for a few seconds after
55+
// spawning to ensure the player has enough
56+
// time to safely move away from asteroids
57+
this.gameObject.layer = LayerMask.NameToLayer("Ignore Collisions");
58+
59+
Invoke(nameof(TurnOnCollisions), 3.0f);
60+
}
61+
5262
private void Update()
5363
{
5464
// Activate thrust when pressing the 'w' key or 'up arrow' key
@@ -91,6 +101,11 @@ private void Shoot()
91101
bullet.Project(this.transform.up);
92102
}
93103

104+
private void TurnOnCollisions()
105+
{
106+
this.gameObject.layer = LayerMask.NameToLayer("Player");
107+
}
108+
94109
private void OnCollisionEnter2D(Collision2D collision)
95110
{
96111
// Check if the player crashed into an asteroid

ProjectSettings/Physics2DSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ Physics2DSettings:
5353
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
5454
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
5555
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
56-
m_LayerCollisionMatrix: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcfffffffcfffffff3fffffff3ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
56+
m_LayerCollisionMatrix: ffefffffffefffffffefffffffffffffffefffffffefffffffffffffffffffffffecffffffecffffffe3ffffffe3ffffc8e0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

ProjectSettings/TagManager.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ TagManager:
2020
- Bullet
2121
- Asteroid
2222
- Boundary
23-
-
23+
- Ignore Collisions
2424
-
2525
-
2626
-

0 commit comments

Comments
 (0)