- Home /
i have 2 enemies (prefabs) on the screen and only one is shooting
Hello the problem im having is with my enemies (that ive made in to a prefab) is that i can only get one to shoot from its spawn point the other enemy is shooting from the first enemy in other words when i have 2 enemies on the screen they are both shooting from the first enemies spawnpoint (dualshoot) this is the code im using on the ai.
also instead of using waypoints does anyone know how i get the ai to just flying forward.
var waypoint : Transform[];
var speed : float = 150;
private var currentWaypoint : int;
var prefabRaket:Transform;
var x : int;
var shootForce: float;
function Update () { if(currentWaypoint < waypoint.length){
var target : Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
var velocity = rigidbody.velocity;
if(moveDirection.magnitude < 5){
currentWaypoint++;
}
else{
velocity = moveDirection.normalized * speed;
}
}
rigidbody.velocity = velocity;
if(x==200) {
var instanceRaket = Instantiate(prefabRaket, GameObject.Find("jas/spawn3").transform.position, transform.rotation );
instanceRaket.rigidbody.AddForce(transform.forward * -1 * shootForce);
x=0;
}
x++;
}
Answer by StephanK · Jun 02, 2010 at 10:21 PM
You are instantiating your rockets at GameObject.Find("jas/spawn3").transform.position. I guess that's the name of you enemy object, and its probably the name of ALL enemy objects, so GameObject.Find will return the first object of that name it finds, which is in most cases the one you spawned first. Just spawn the rockets at transform.position and you should be fine.
Answer by superpentil · Aug 21, 2010 at 05:55 AM
make sure the target is set to you or the character the person will be playing, if you need to
Your answer
Follow this Question
Related Questions
Using box collider to determine if AI should stop help 1 Answer
My AI is flying when I jump 2 Answers
OnTriggerEnter/Exit at speed 1 Answer
Help with a simple AI 2 Answers
Clearing a destination... 1 Answer