Created
November 14, 2021 15:11
-
-
Save didacus/5a9c9c851e2c43329921cee2508c048b to your computer and use it in GitHub Desktop.
Unity - Enemy controller that follows player.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class EnemyController : MonoBehaviour | |
{ | |
private Rigidbody RB; | |
public float moveSpeed; | |
public PlayerController thePlayer; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
RB = GetComponent<Rigidbody>(); | |
thePlayer = FindObjectOfType<PlayerController>(); | |
} | |
void FixedUpdate() | |
{ | |
RB.velocity = (transform.forward * moveSpeed); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
transform.LookAt(thePlayer.transform.position); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment