Merge branch 'stab' into mainMenu

This commit is contained in:
2024-10-26 23:53:46 -07:00
5 changed files with 33 additions and 20 deletions

View File

@@ -29,7 +29,7 @@ Transform:
m_GameObject: {fileID: 398740452138961375}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -11.37, y: -2.4779136, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.45, y: 0.45, z: 0.45}
m_ConstrainProportionsScale: 1
m_Children: []

View File

@@ -100,4 +100,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 23dc3f32eba4c9e5aad24589fdbfa30c, type: 3}
m_Name:
m_EditorClassIdentifier:
multiplier: 2.8
multiplier: 1

View File

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

View File

@@ -325,7 +325,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
propertyPath: swingDistance
value: 2
value: 3
objectReference: {fileID: 0}
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
propertyPath: swingRangeDeg
value: 10
objectReference: {fileID: 0}
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
propertyPath: distanceIndicator

View File

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