Merge branch 'stab' into mainMenu
This commit is contained in:
@@ -29,7 +29,7 @@ Transform:
|
|||||||
m_GameObject: {fileID: 398740452138961375}
|
m_GameObject: {fileID: 398740452138961375}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
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_LocalScale: {x: 0.45, y: 0.45, z: 0.45}
|
||||||
m_ConstrainProportionsScale: 1
|
m_ConstrainProportionsScale: 1
|
||||||
m_Children: []
|
m_Children: []
|
||||||
|
|||||||
@@ -100,4 +100,4 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 23dc3f32eba4c9e5aad24589fdbfa30c, type: 3}
|
m_Script: {fileID: 11500000, guid: 23dc3f32eba4c9e5aad24589fdbfa30c, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
multiplier: 2.8
|
multiplier: 1
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -325,7 +325,11 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
||||||
propertyPath: swingDistance
|
propertyPath: swingDistance
|
||||||
value: 2
|
value: 3
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
||||||
|
propertyPath: swingRangeDeg
|
||||||
|
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
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public class Teo : MonoBehaviour
|
|||||||
public float swingDistance = 10;
|
public float swingDistance = 10;
|
||||||
public float damageStrength = 10;
|
public float damageStrength = 10;
|
||||||
public float attackCooldownSeconds = 10;
|
public float attackCooldownSeconds = 10;
|
||||||
|
public float spamPunishMultiplier = 0.5F;
|
||||||
public float dashDistance = 5F;
|
public float dashDistance = 5F;
|
||||||
public float dashCooldownSeconds = 5;
|
public float dashCooldownSeconds = 5;
|
||||||
public float lastAttackTime = 0;
|
public float lastAttackTime = 0;
|
||||||
@@ -43,9 +44,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,36 +53,47 @@ 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.
|
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
|
// Calculate absolute difference between angles of ratbot and cursor
|
||||||
/* if (ratbot == null || Mathf.Abs(Mathf.Atan2(
|
if (Mathf.Abs(Mathf.Atan2(
|
||||||
ratbot.transform.position.y - transform.position.y,
|
hitClosest.y - transform.position.y,
|
||||||
ratbot.transform.position.x - transform.position.x
|
hitClosest.x - transform.position.x
|
||||||
) - Mathf.Atan2(
|
) - Mathf.Atan2(
|
||||||
Screen.height/2 - Input.mousePosition.y,
|
Input.mousePosition.y - Screen.height/2,
|
||||||
Screen.width/2 - Input.mousePosition.x
|
Input.mousePosition.x - Screen.width/2
|
||||||
)) > swingRangeDeg * Mathf.Deg2Rad
|
)) > swingRangeDeg * Mathf.Deg2Rad
|
||||||
) */
|
) continue;
|
||||||
if (ratbot == null) {
|
// Apply a multiplier to damageStrength based on attack cooldown.
|
||||||
continue;
|
// If multiplier > 1, just do damageStrength
|
||||||
}
|
float damageAmount = damageStrength * (Time.fixedTime - lastAttackTime)/attackCooldownSeconds;
|
||||||
|
ratbot.Damage(
|
||||||
ratbot.Damage(damageStrength);
|
(damageAmount > damageStrength)
|
||||||
|
? damageStrength
|
||||||
|
: damageAmount * spamPunishMultiplier
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user