i already made this one :
using UnityEngine;
using System.Collections;
public class EnnemiScript : MonoBehaviour {
public float m_dov;
public float m_speed = 2f;
public GameObject dalila;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
GameObject cible = null;
Collider[ ] colliders = Physics.OverlapSphere(transform.position, m_dov);
if (colliders.Length > 1)
{
foreach (Collider ColliderCurrent in colliders)
{
if (ColliderCurrent.gameObject != gameObject)
{
cible = ColliderCurrent.gameObject;
print(“bonjour”);
Debug.DrawLine(transform.position, ColliderCurrent.transform.position);
}
}
}
//dalila.transform.position=Vector3(cible.transform.position.x-1,cible.transform.position.y-1,cible.transform.position.z-1);
Vector3 v2cible = cible.transform.position - transform.position;
//Vector3 v2=transform.Translate(-1f,-1f,0);
print(cible.transform.position.x);
v2cible.Normalize();
v2cible *= m_speed;
v2cible *= Time.deltaTime;
transform.Translate(v2cible);
}
}
its works but it seems to have something wrong cause the follower takes exactly the same position as the target and stuck to it, and me, i want that the follower to stop close to the target but not in the same position as it.
so i tried this one :
var target : Transform;
function Update(){
var right = transform.TransformDirection(Vector3.right);
var left = transform.TransformDirection(Vector3.left);
var fwd = transform.TransformDirection(Vector3.forward);
if (!Physics.Raycast(transform.position, fwd, 20) !Physics.Raycast(transform.position, right, 40) !Physics.Raycast(transform.position, left, 40)){
transform.Translate(Vector3.zero);
transform.LookAt(target);
transform.Translate(Vector3.forward * 15 * Time.deltaTime);
}
else if (!Physics.Raycast(transform.position, fwd, 20)) {
transform.Translate(Vector3.zero);
transform.Translate(Vector3.forward * 15 * Time.deltaTime);
}
else if (!Physics.Raycast(transform.position, right, 40)) {
transform.Translate(Vector3.zero);
transform.Rotate(0,25,0);
}
else if (!Physics.Raycast(transform.position, left, 40)) {
transform.Translate(Vector3.zero);
transform.Rotate(0,25,0);
}
}
}
this one too works but the follower do the job lying down on the belly so … please help me and if you can correct the mistakes or suggest me an other script it will be very nice of you thanks :-*