var player: GameObject;
var enemy : Transform;
private var timer: float;
var seenDistance = 40;
var rotationSpeed = 100;
var moveSpeed = 5;
function Awake()
{
timer = Time.time + 10;
}
function Start ()
{
}
function Update ()
{
var distance = Vector3.Distance(transform.position, player.transform.position);
if(distance < seenDistance)
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(player.transform.position - transform.position),rotationSpeed * Time.deltaTime);
transform.position += transform.forward * moveSpeed * Time.deltaTime;
if (timer < Time.time)
{
Instantiate(enemy, transform.position, transform.rotation);
timer = Time.time + 10;
}
}
}
This is the code for my enemy, i have it set up so that when the player gets within the distance of an enemy, it will start to spawn more and more enemies. This works the way i want.
What i need help with is the spawn function creates the enemy on top of the other enemy and as a result, the spawned enemy gets launched into the air for a short time.
Is there a way i can spawn the enemy to a slight offset of the enemy it's being created from?
Any replies appreciated.
↧