Apply multiplier to damage strength based on attack cooldown

This commit is contained in:
2024-10-26 23:32:16 -07:00
parent e3c8dfcfa7
commit de3873f590
3 changed files with 15 additions and 11 deletions

View File

@@ -106,8 +106,8 @@ MonoBehaviour:
health: 100 health: 100
maxHealth: 100 maxHealth: 100
moveSpeed: 15 moveSpeed: 15
swingRange: 2 swingRangeDeg: 3
swingDistance: 10 swingDistance: 2
damageStrength: 10 damageStrength: 10
attackCooldownSeconds: 2 attackCooldownSeconds: 2
dashDistance: 20 dashDistance: 20

View File

@@ -329,7 +329,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3} - target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
propertyPath: swingRangeDeg propertyPath: swingRangeDeg
value: 21.98 value: 10
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3} - target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
propertyPath: distanceIndicator propertyPath: distanceIndicator

View File

@@ -43,9 +43,6 @@ public class Teo : MonoBehaviour
} }
} }
void Attack() { void Attack() {
if (Time.fixedTime-lastAttackTime < attackCooldownSeconds) {
return;
}
Instantiate(distanceIndicator, transform); Instantiate(distanceIndicator, transform);
// Get all objects within swingDistance of player // Get all objects within swingDistance of player
Collider2D[] hits = Physics2D.OverlapCircleAll( Collider2D[] hits = Physics2D.OverlapCircleAll(
@@ -55,13 +52,13 @@ public class Teo : MonoBehaviour
// Damage all ratbots in scanned area // Damage all ratbots in scanned area
foreach (Collider2D hit in hits) { foreach (Collider2D hit in hits) {
Ratbot ratbot = hit.GetComponent<Ratbot>(); Ratbot ratbot = hit.GetComponent<Ratbot>();
// If ratbot exists and is within swing range, damage it.
// Calculate absolute difference between angles of ratbot and cursor
if (ratbot == null) continue; if (ratbot == null) continue;
// Find the closest point on the ratbot
Vector2 hitClosest = Physics2D.ClosestPoint( Vector2 hitClosest = Physics2D.ClosestPoint(
transform.position, transform.position, hit
hit
); );
// If ratbot's closest point within swing range, damage it.
// Calculate absolute difference between angles of ratbot and cursor
if (Mathf.Abs(Mathf.Atan2( if (Mathf.Abs(Mathf.Atan2(
hitClosest.y - transform.position.y, hitClosest.y - transform.position.y,
hitClosest.x - transform.position.x hitClosest.x - transform.position.x
@@ -70,22 +67,29 @@ public class Teo : MonoBehaviour
Input.mousePosition.x - Screen.width/2 Input.mousePosition.x - Screen.width/2
)) > swingRangeDeg * Mathf.Deg2Rad )) > swingRangeDeg * Mathf.Deg2Rad
) continue; ) continue;
ratbot.Damage(damageStrength); // Apply a multiplier to damageStrength based on attack cooldown.
// If multiplier > 1, just do damageStrength
// Fuck readability, it's a one liner now
Debug.Log(Mathf.Min(damageStrength * (Time.fixedTime - lastAttackTime)/attackCooldownSeconds, damageStrength));
ratbot.Damage(Mathf.Min(damageStrength * (Time.fixedTime - lastAttackTime)/attackCooldownSeconds, damageStrength));
} }
} }
IEnumerator Dash() { IEnumerator Dash() {
BoxCollider2D collider = GetComponent<BoxCollider2D>(); BoxCollider2D collider = GetComponent<BoxCollider2D>();
// Disable collision and linearDamping while dashing
lastDashTime = Time.fixedTime; lastDashTime = Time.fixedTime;
dashing = true; dashing = true;
collider.enabled = false; collider.enabled = false;
controller.linearDamping = 0; controller.linearDamping = 0;
controller.linearVelocity = Vector2.zero; controller.linearVelocity = Vector2.zero;
// Apply a force to player towards mouse cursor
controller.AddRelativeForce (new Vector2( controller.AddRelativeForce (new Vector2(
Input.mousePosition.x - Screen.width/2, Input.mousePosition.x - Screen.width/2,
Input.mousePosition.y - Screen.height/2 Input.mousePosition.y - Screen.height/2
).normalized * dashDistance); ).normalized * dashDistance);
// Wait 0.2 seconds before ending the dash // Wait 0.2 seconds before ending the dash
yield return new WaitForSeconds(0.2F); yield return new WaitForSeconds(0.2F);
// Re enable collision and linearDamping after dash complete
dashing = false; dashing = false;
collider.enabled = true; collider.enabled = true;
controller.linearDamping = 15; controller.linearDamping = 15;