Spawn enemy at an offset

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.

I think you need this:

The easiest way to do this is to add a simple offset to your class:

var offsetX = 5;
var offsetZ = 5;

function Update()
{
     // your stuff here up to the timer check

     if(timer < Time.time)
     {
           var offset = Vector3(Random.Range(-offsetX, offsetX), 0, Random.Range(-offsetZ, offsetZ));
           Instantiate(enemy, transform.position + offset, transform.rotation);
           timer = Time.time + 10;
     }
}