Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class enemy_ai : MonoBehaviour {
- public GameObject player_obj;
- int health = Mathf.Floor (Random.Range (3,6));
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- float direction_to_player = Mathf.Atan2 (player_obj.transform.position.x - transform.position.x, player_obj.transform.position.z - transform.position.z);
- GetComponent<Rigidbody>().velocity = new Vector3(1f*Mathf.Sin (direction_to_player),0,1f*Mathf.Cos (direction_to_player));
- transform.LookAt (transform.position + GetComponent<Rigidbody> ().velocity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement