Advertisement
Guest User

Enemy'sCodemibytes2015

a guest
Jul 7th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class enemy_ai : MonoBehaviour {
  5. public GameObject player_obj;
  6. int health = Mathf.Floor (Random.Range (3,6));
  7. // Use this for initialization
  8. void Start () {
  9.  
  10. }
  11.  
  12. // Update is called once per frame
  13. void Update () {
  14. float direction_to_player = Mathf.Atan2 (player_obj.transform.position.x - transform.position.x, player_obj.transform.position.z - transform.position.z);
  15. GetComponent<Rigidbody>().velocity = new Vector3(1f*Mathf.Sin (direction_to_player),0,1f*Mathf.Cos (direction_to_player));
  16. transform.LookAt (transform.position + GetComponent<Rigidbody> ().velocity);
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement