I need to instantiate a empty gameObject 2 Units right/left of a 'Enemies' Transform?

Hello, I need to instantiate a empty gameObject/Waypoint 2 Units right/left of a ‘Enemies’ Transform? I am making the enemies AI and need to drop a Waypoint either right or left of the enemy so if the enemy collids with a say a rock the enemy looks at the newly created Waypoint and goes to that Waypoint and then the Waypoint destories itself when triggered. The enemy then looks at the main object that it was trying to get to get to like in RTS Games… I hope that makes sense :stuck_out_tongue:

Well, to get the position left or right, just find the point left or right of where your enemy is. Here is some untested, top of my head, code ( c# ):

Transform enemyTransform; //set this to the enemy, however you want
Transform newTransform = enemyTransform;
float amount = 2.0f; //amount to check

newTransform.Translate(Vector3.right * amount); //move right
Instantiate(wayPointPrefab, newTransform.position, Quaternion.zero);
//this assumes a prefab has been loaded into wayPointPrefab, use Resources.Load for this or inspector variable
//Quaternion.zero rotation orients to world zero rotation, if you need something different use that, you could also use enemyTransform.rotation

I believe this will work fine.
There might be a quicker way to do this with directly modifying x,y, or z components of newTransform.position, but this was the first way I thought of.

When you say right or left, it usually means you’re thinking in local coordinates (select a rotated object in the editor and toggle Local/Global at top-left to see the difference.) Your right, of the way you are facing now.

To move two units right (your right, local): Vector3 p2 = transform.position + transform.right*2;. Trans.right is essentially the little Red direction arrow when you’re moving an object.

To compare, world movement (east, in this case) is transform.position + Vector3.right*2;

If you’re lying on your side, transform.right could be up or down, but a typical “mob” is always head-up, so transform.L/R/F/B is always flat along the ground.

i figured it out myself. This is what I used!

var CreateWaypoint = false;

function Upadate(){

if(CreateWaypoint == true){
    var CorrectionWay = instantiate(CorrectionWaypoint, Vector3(transform.localPosition * 2.3f, transform.localPosition.y, transform.localPosition.z), transform.rotation); 
    
    CorrectionWay.name = "WayPoint";
CreateWaypoint = false;

}
}

This creates a waypoint about 2 units to the left of the enemy