I want to make my enemy move towards my character in the x axis, but he moves on the z axis instead. I’m not too good with scripting so here is my script and tell me what am I doing wrong.
using UnityEngine;
using System.Collections;
public class EnemyAi : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxDistance;
private Transform myTransform;
void Awake() {
myTransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
maxDistance = 2;
}
// Update is called once per frame
void FixedUpdate () {
Debug.DrawLine(target.position, myTransform.position, Color.yellow);
//Look at target
//Move towards target
myTransform.position -= myTransform.forward * moveSpeed * Time.deltaTime;
}
}