x


shooting multiple projectiles at enemies

hi again..

i need some help on this topic here...

i'll post a youtube link and describe it as well...

http://www.youtube.com/watch?v=C4iO1Gl7wiA

its from Tom Calancy's HAWX..

i want to create multiple bullets/ missiles/ etc.. to my space ship..

similar to the youtube clip..

does anyone have any ideas on doing this??

thanks for reading.. and your patience is highly appreciated..

more ▼

asked Jun 20 '12 at 08:21 AM

zerox911 gravatar image

zerox911
130 12 21 23

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

1 answer: sort voted first

All shots are 'instances' meaning a "shallow copy" of the original. They reference the same /mesh,position,rotation,etc/ of the original but will not be as costly as a "New" version of that prefab. In this case you will have one MAIN version of the shot (var myRocket) which can now be used in (var rocket=Instantiate(myRocket,'somePosition',Quaternion.identity) which makes the shallow copy, not quite as processor intensive as creating that same object from scratch with the same mesh,position,rotation as the original. In doing so you create a new way for unity to look at this "new" object(reference to the original), instead of looking at it as a completely new object entirely. This save speed and lines of code, and will be able to create 10 instances faster than 1 new org object of the same type.

more ▼

answered Jun 20 '12 at 08:48 AM

hijinxbassist gravatar image

hijinxbassist
2k 23 31 38

If you are shooting on one script...say something like the previous idea

var myRocket:Transform;

function Shoot()
{
    var rocket=Instantiate(myRocket,transform.position,Quaternion.identity);

    //rocket.doSomethingElse;
    //Maybe make a var on rocket true, or speed faster, or any number of things
    //be creative but be logical in doing so(fill Shoot overload with speed etc..
}
Jun 20 '12 at 08:54 AM hijinxbassist

thanks... i'll try it.. but i need some more reference and some snippet codes or something..

appreciate it @hijinxbassist..

Jun 20 '12 at 09:18 AM zerox911

Since you dont have any code in your questions its tough to guess the proper coding technique. This is a basic structure which i provide, here is a little more on top of that..again tough to give specifics w.o actually code present

//On Player
//cur shot is determined from a series of actions
//the cur shot may be 1,2,3,etc if the weapons are
//set as so(maybe) add(if input getButton(1) curShot="SomeShot")
//i cant be more specifice w.o specific code
//canFire is a boolean to dealy shot time(if true plr can shoot)

function Update()
{
     if(Input.GetButtonDown("Fire")
     {
         if(canFire)Shoot(curShot,2);
     }
}
function Shoot(shotType:Transform,shotLife:float)
{
    var shot=Instantiate(shotType,transform.forward,transform.rotation);
    shot.GetComponent(Shot).shotLife==shotLife;//Makes the shotLife 2
    //granted shotType has a Comonent(Shot) and a variable called shotLife
    //the basic idea is:(shotLife==how long shot is active in scene)
    //which is define on a separate script(Shot) which is attached to
    //the curShot(a variable which may change, num1=pistol, num2=shotgun)
}
Jun 20 '12 at 11:18 AM hijinxbassist
(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:

x291
x69
x15
x4

asked: Jun 20 '12 at 08:21 AM

Seen: 389 times

Last Updated: Jun 20 '12 at 11:35 AM