Health system + Water Spirit AI!

This commit is contained in:
MindfulMinun committed 2022-02-25 13:12:42 -06:00
1 parent f3985d657e
commit 827588bb18
7 files changed
+281 -33

No files matched your search

+10 -1
View File
@@ -4,6 +4,7 @@ using UnityEngine;
public class WaterSpirit : MonoBehaviour {
private Transform player;
public BoxCollider2D boxCollider;
public float swimSpeed = .25f;
private Rigidbody2D rb;
private Vector2 movement = Vector2.zero;
@@ -11,6 +12,7 @@ public class WaterSpirit : MonoBehaviour {
void Start() {
rb = this.GetComponent<Rigidbody2D>();
boxCollider = this.GetComponent<BoxCollider2D>();
sizeOffset = Random.Range(2f, 10f);
player = GameObject.FindWithTag("Player").transform;
if (player == null) {
@@ -23,14 +25,21 @@ public class WaterSpirit : MonoBehaviour {
Vector3 direction = player.position - transform.position;
movement = direction.normalized;
// Scale spirit size so they look like the swim like squid lol
float size = Mathf.Sin(Time.time * sizeOffset) + 4;
float size = Mathf.Sin(Time.time * sizeOffset) * .25f + 1;
transform.localScale = new Vector3(size, size, 1);
}
void FixedUpdate() {
if (Movement.pause) return;
moveMe(movement);
}
private void OnTriggerEnter2D(Collider2D collision) {
if (collision.tag == "Player") {
collision.GetComponent<Health>().takeHit();
}
}
void moveMe(Vector2 direction) {
rb.MovePosition(rb.position + direction * swimSpeed * Time.fixedDeltaTime);
}