What I’m trying to do is have the object this script is attached to move toward it’s target when the player enters it’s trigger. It actually STARTS to work, but the object stops moving instantly after it starts. Meaning it just moves about an inch then stops. This is a script from the forums that I’ve slightly modified for what I need. Please note that I’m still a beginner at scripting, and after hours of frustration, I still can’t get this object to move towards the target when the player enters it’s trigger. Can someone please tell me what I’m doing wrong here?
var player : GameObject;
var speed : float = 1;
function Start ()
{
player = GameObject.FindGameObjectWithTag(“CarrieTarget1”);
if (!player)
Debug.Log ("ERROR could not find Player!");
}
function OnTriggerEnter (other : Collider) {
if (!player)
return;
var distance = Vector3.Distance( player.transform.position, transform.position);
if ( distance < 100 )
{
Debug.Log ("player is close");
if ( distance < 1 )
Destroy (gameObject);
var delta = player.transform.position - transform.position;
delta.Normalize();
var moveSpeed = speed * Time.deltaTime;
transform.position = transform.position + (delta * moveSpeed);
}
else
{
Debug.Log("not close yet " + distance);
}
}