x


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++;

}
more ▼

asked Jun 02 '10 at 06:18 PM

Marcus gravatar image

Marcus
41 6 6 11

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Jun 02 '10 at 10:21 PM

StephanK gravatar image

StephanK
6k 39 53 93

(comments are locked)
10|3000 characters needed characters left

make sure the target is set to you or the character the person will be playing, if you need to

more ▼

answered Aug 21 '10 at 05:55 AM

superpentil gravatar image

superpentil
13 1 8 10

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x959
x440
x329
x170
x46

asked: Jun 02 '10 at 06:18 PM

Seen: 1125 times

Last Updated: Jun 02 '10 at 06:49 PM