Skip to content

Commit ee35554

Browse files
committed
Obstacle jump height + double damage fix + player physics
Added Cooldown timer 0.5sec for double damage deduction
1 parent 8a70d6a commit ee35554

4 files changed

Lines changed: 53 additions & 5 deletions

File tree

Assets/2D Platformer/Scripts/PlayerController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ public class PlayerController : MonoBehaviour
1010
{
1111
public float movingSpeed;
1212
public float jumpForce;
13+
public float healthRegenerationRate;
1314
private float moveInput;
1415
private bool jumpFlag = false;
1516
private bool keyboardControlFlag = false;
17+
private float lastDamageTime = -Mathf.Infinity; // track last damage time
18+
public float damageCooldown = 0.5f; // 0.5 second cooldown
1619

1720
private bool facingRight = false;
1821
[HideInInspector]
@@ -152,11 +155,12 @@ private void CheckGround()
152155

153156
private void OnCollisionEnter2D(Collision2D other)
154157
{
155-
if (other.gameObject.tag == "Enemy")
158+
if (other.gameObject.tag == "Enemy" && (Time.time - lastDamageTime > damageCooldown))
156159
{
157160
//deathState = true; // Say to GameManager that player is dead
158-
healthBar.setHealth(healthBar.healthSlider.value - 20);
159-
rigidbody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
161+
healthBar.setHealth(healthBar.healthSlider.value - healthRegenerationRate);
162+
lastDamageTime = Time.time; // reset cooldown timer
163+
rigidbody.AddForce(transform.up * jumpForce/2, ForceMode2D.Impulse);
160164
Debug.Log("Player hit by enemy. Health: " + healthBar.healthSlider.value);
161165
}
162166

Assets/Scenes/EasyLevel.unity

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,10 +2439,34 @@ PrefabInstance:
24392439
propertyPath: m_Name
24402440
value: Player
24412441
objectReference: {fileID: 0}
2442+
- target: {fileID: 6952628394585513908, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
2443+
propertyPath: m_Mass
2444+
value: 1.3
2445+
objectReference: {fileID: 0}
2446+
- target: {fileID: 6952628394585513908, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
2447+
propertyPath: m_UseAutoMass
2448+
value: 0
2449+
objectReference: {fileID: 0}
2450+
- target: {fileID: 6952628394585513908, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
2451+
propertyPath: m_GravityScale
2452+
value: 1.5
2453+
objectReference: {fileID: 0}
2454+
- target: {fileID: 6952628394585513908, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
2455+
propertyPath: m_LinearDamping
2456+
value: 1
2457+
objectReference: {fileID: 0}
24422458
- target: {fileID: 6952628394585513909, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
24432459
propertyPath: healthBar
24442460
value:
24452461
objectReference: {fileID: 1980057119}
2462+
- target: {fileID: 6952628394585513909, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
2463+
propertyPath: jumpForce
2464+
value: 13.5
2465+
objectReference: {fileID: 0}
2466+
- target: {fileID: 6952628394585513909, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
2467+
propertyPath: healthRegenerationRate
2468+
value: 10
2469+
objectReference: {fileID: 0}
24462470
- target: {fileID: 6952628394585513910, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
24472471
propertyPath: m_FlipX
24482472
value: 0

Assets/Scenes/MediumLevel.unity

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25651,10 +25651,30 @@ PrefabInstance:
2565125651
propertyPath: m_Name
2565225652
value: Player
2565325653
objectReference: {fileID: 0}
25654+
- target: {fileID: 6952628394585513908, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
25655+
propertyPath: m_Mass
25656+
value: 1.3
25657+
objectReference: {fileID: 0}
25658+
- target: {fileID: 6952628394585513908, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
25659+
propertyPath: m_GravityScale
25660+
value: 1.5
25661+
objectReference: {fileID: 0}
25662+
- target: {fileID: 6952628394585513908, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
25663+
propertyPath: m_LinearDamping
25664+
value: 1
25665+
objectReference: {fileID: 0}
2565425666
- target: {fileID: 6952628394585513909, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
2565525667
propertyPath: healthBar
2565625668
value:
2565725669
objectReference: {fileID: 1828255258}
25670+
- target: {fileID: 6952628394585513909, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
25671+
propertyPath: jumpForce
25672+
value: 13.5
25673+
objectReference: {fileID: 0}
25674+
- target: {fileID: 6952628394585513909, guid: a3dc7dd79a2fbc341a3fc828503f1ca9, type: 3}
25675+
propertyPath: healthRegenerationRate
25676+
value: 20
25677+
objectReference: {fileID: 0}
2565825678
m_RemovedComponents: []
2565925679
m_RemovedGameObjects: []
2566025680
m_AddedGameObjects: []

Assets/Scripts/CameraScaler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ private void AdjustCameraSize()
2525

2626
float aspect = (float)Screen.width / Screen.height;
2727

28-
Debug.Log(Screen.width);
29-
Debug.Log(aspect);
28+
//Debug.Log(Screen.width);
29+
//Debug.Log(aspect);
3030

3131
/* Aspect Ratio Notes
3232
1.77 => 8 //Typical Desktop

0 commit comments

Comments
 (0)