Added ratbot enemies that move towards the player

This commit is contained in:
2024-10-19 17:47:28 -07:00
parent 40deb627bd
commit de624d838f
14 changed files with 636 additions and 155 deletions

20
Assets/Ratbot.cs Normal file
View File

@@ -0,0 +1,20 @@
using UnityEngine;
public class Ratbot : MonoBehaviour
{
public float moveSpeed;
GameObject player;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
}
// Update is called once per frame
void Update()
{
Rigidbody2D controller = GetComponent<Rigidbody2D>();
Vector2 direction = (player.transform.position - transform.position).normalized;
controller.linearVelocity = direction*moveSpeed;
}
}