Hello,
I'm gettin gy hands dirty to learn a bit of math, and Unity again. I'm trying to move the gameObject transform to a mid point from player.transform to transform.location.
It's just some dummy ai, so nothing major going on.
Right now the baddy, which is gameObject doesn't move anywhere in the Vector3.Lerp.
Thanks for help.
using UnityEngine;
using System.Collections;
public class bad : MonoBehaviour {
private Vector2 speed;
public Transform player;
private bool playerDetected;
private Vector3 destinationVector;
private Vector3 destinationPoint;
private bool moveComplete;
// player rotation
private Vector3 zAxis = new Vector3(0, 0, 1);
// Use this for initialization
void Start () {
speed.x = 1.0f;
speed.y = 1.0f;
playerDetected = false;
moveComplete = false;
}
// Update is called once per frame
void Update () {
if (!moveComplete) {
Vector3 destinationVector = player.transform.position - transform.position;
destinationPoint = new Vector3(destinationVector.x + transform.position.x / 2.0f, destinationVector.y - transform.position.y / 2.0f, 0.0f);
}
if (playerDetected) {
// transform.RotateAround (player.transform.position, zAxis, 0.5f);
} else {
if(!moveComplete)
{
Vector3.Lerp(transform.position,destinationPoint, 1.0f * Time.deltaTime);
if(Vector3.Distance(transform.position, destinationPoint) <= 8)
{
moveComplete = true;
}
}
}
if(Vector3.Distance(player.transform.position, transform.position) <= 8)
{
playerDetected = true;
}else{
playerDetected = false;
}
}
}