Skip to content
Snippets Groups Projects
Commit e91488fd authored by Mitchel Kovacs (mdk181)'s avatar Mitchel Kovacs (mdk181)
Browse files

makes enemies chase player

parent 6c8682b9
No related branches found
No related tags found
No related merge requests found
using UnityEngine;
using System.Collections;
public class InBetweenAI : MonoBehaviour {
private Animator myAnimator;
private Transform target;
private float speed = 3;
bool moveallowed = false;
double[] heights = { -1.40, 1, 3.12, 5.33, 7.58 };
// Use this for initialization
// Use this for initialization
void Start () {
target = GameObject.FindGameObjectWithTag("Player").transform;
}
// Update is called once per frame
void Update () {
myAnimator = GetComponent<Animator>();
move();
}
public void move()
{
if (moveallowed)
{
Debug.Log("moving");
//rotate to look at the player
//transform.LookAt(target.position);
myAnimator.SetFloat("speed", 1); // This should probbaly reflect the actual speed
transform.position = Vector2.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime);
if (target.transform.position.x <= transform.position.x) //players spot in world space as opposed to enemy "self" spot
{
transform.rotation = new Quaternion(0, 180, 0, 0); // flips enemy around to face the player on x axis only
}
else if (target.transform.position.x >= transform.position.x) //players spot in world space as opposed to enemy "self" spot
{
transform.rotation = new Quaternion(0, 0, 0, 0); // flips enemy around to face the player on x axis only }
}
if(Vector3.Distance(transform.position, target.transform.position) < 1 )
{
moveallowed = false;
Debug.Log("collide");
//load combat scene
}
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.name == "Player")
{
moveallowed = true;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment