@@ -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
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class Ratbot : MonoBehaviour
|
|||||||
|
|
||||||
// Die if health below zero
|
// Die if health below zero
|
||||||
public void Damage(float hurtyAmount) {
|
public void Damage(float hurtyAmount) {
|
||||||
|
Debug.Log(hurtyAmount);
|
||||||
health -= hurtyAmount;
|
health -= hurtyAmount;
|
||||||
if (health <= 0) {
|
if (health <= 0) {
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
|
|||||||
@@ -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,36 +52,49 @@ 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 x^2 multiplier to damage if not fully charged
|
||||||
continue;
|
// Just use damageStrength if fully charged
|
||||||
}
|
float timeWaited = Time.fixedTime - lastAttackTime;
|
||||||
|
ratbot.Damage(
|
||||||
ratbot.Damage(damageStrength);
|
(timeWaited < attackCooldownSeconds)
|
||||||
|
? Mathf.Pow(timeWaited, 2) *
|
||||||
|
damageStrength /
|
||||||
|
Mathf.Pow(attackCooldownSeconds, 2)
|
||||||
|
: 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user