Skip to content

Instantly share code, notes, and snippets.

@adamtuliper
Created April 9, 2021 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamtuliper/12ad566168db55ba796a5e2c327eb2e4 to your computer and use it in GitHub Desktop.
Save adamtuliper/12ad566168db55ba796a5e2c327eb2e4 to your computer and use it in GitHub Desktop.
Enemy moving away from the player but looking at them
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