Hi,
I created enemy sphere (a ball) that follows my player hit it or touch it and player dead or decreased power.
but i can’t able to script it properly. I use this code in my Sphere(Ball Enemy to gave it AI) But it does not rotate & i didn’t know how to add rotate line or something in my code) can you please help me .
I need real-time rotation when it’s following my player . With this script the enemy does not rotates it follows up my player just track or drag like . it does not rotating like the ball walking . Please help me .
here in c# . Here is my video with my problem … Golden ball is mine and the other rocks grey enemy following me without spinning - - YouTube
using UnityEngine;
using System.Collections;
public class EnemyAI: MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
private Transform myTransform;
void Awake(){
myTransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
}
// Update is called once per frame
void Update () {
Debug.DrawLine(target.position, myTransform.position, Color.cyan);
//look at target
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
//move towards target
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}