Created
April 9, 2021 17:29
-
-
Save adamtuliper/12ad566168db55ba796a5e2c327eb2e4 to your computer and use it in GitHub Desktop.
Enemy moving away from the player but looking at them
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; | |
private Transform playerTransform; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
rb = GetComponent<Rigidbody>(); | |
playerTransform = GameObject.FindWithTag("Player").transform; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
transform.LookAt(playerTransform); | |
} | |
void FixedUpdate() | |
{ | |
rb.velocity = transform.TransformDirection(Vector3.back); | |
Debug.Log("rb vel: " + rb.velocity); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment