Commit 33bc2884 authored by RaptorTwitch's avatar RaptorTwitch

Added SeekerAI;

parent badb74f5
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SeekerAI : MonoBehaviour
{
public float vel = 2.5f;
public GameObject vomit;
public float rotationVel = 2.5f;
private GameObject player;
public GameObject[] TurretAnchor;
private Transform[] navpoints = new Transform[18];
private bool alive = false;
private Transform spawnPoint;
private GameMaster gm;
private ToidHeart th;
private Collider coll;
private int dest = 0;
private bool canFire = false;
public float firerate = 0.25f;
private Animator animator;
// Start is called before the first frame update
void Start()
{
th = gameObject.GetComponent<ToidHeart>();
animator = GetComponent<Animator>();
}
public void setNavPoints(Transform[] tileNavPoints)
{
navpoints = tileNavPoints;
}
public void setGameMaster(GameMaster gamemaster)
{
gm = gamemaster;
}
public void setPlayer(GameObject playerM)
{
player = playerM;
}
public ToidHeart getHeart()
{
return th;
}
public void activate()
{
alive = true;
StartCoroutine("ShotDelay");
}
// Update is called once per frame
void Update()
{
if(alive && player != null)
{
transform.position = Vector3.MoveTowards(transform.position, navpoints[dest].position, vel * Time.deltaTime);
if (Vector3.Distance(transform.position, navpoints[dest].position) == 0 && dest < navpoints.Length - 1)
{
dest = Random.Range(0, 18);
}
Vector3 pos = player.transform.position - transform.position;
Transform turtletarget = transform;
if(Vector3.Distance(transform.position, TurretAnchor[0].transform.position) < Vector3.Distance(transform.position, TurretAnchor[1].transform.position))
{
turtletarget.position = Vector3.MoveTowards(transform.position, TurretAnchor[0].transform.position, vel * Time.deltaTime);
}
else
{
turtletarget.position = Vector3.MoveTowards(transform.position, TurretAnchor[1].transform.position, vel * Time.deltaTime);
}
if((Vector3.Distance(turtletarget.position, TurretAnchor[0].transform.position) == 0) || (Vector3.Distance(turtletarget.position, TurretAnchor[1].transform.position) == 0))
{
//transform.LookAt(Vector3.Lerp(transform.position, player.transform.position, 20.0f * Time.deltaTime));
Vector3 target = player.transform.position - transform.position;
target.y = 0.0f;
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(target), Time.deltaTime * rotationVel);
if(canFire)
{
canFire = false;
EnemyBullet bullet = gm.getBullet();
bullet.transform.position = transform.position;
bullet.transform.rotation = transform.rotation;
bullet.activate();
StartCoroutine("DelayFire");
}
}
animator.SetFloat("velForward", -(navpoints[dest].position - transform.position).z);
animator.SetFloat("velRight", -(navpoints[dest].position - transform.position).x);
}
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Player")
{
other.GetComponent<ShipLogic>().takeHit(1);
}
}
IEnumerator DelayFire()
{
float rng = Random.Range(1, 3);
yield return new WaitForSeconds(rng);
canFire = true;
}
}
fileFormatVersion: 2
guid: 5171ed1e23f0f304494186a7e109be60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment