I know this question is probably very redundant, but please hear me out.
I'm trying to understand some of the pros and cons, along with the finer details of methods used for lasers, bullets, and so on.
So finally, here is what I am looking for specifically:
Any help will be GREATLY appreciated. I'm building it for computer, so I'm not trying to cram this onto an iPhone, though I'd still like to try and keep it optimized.
Well, this is a bit of a huge question. I'll try to address it point by point!
Assuming you have a single script which you set up in the inspector for different kinds of projectiles (despite how horrendously unrealistic slow lasers are, but that doesn't matter), your script needs to have the following-
Now, it's kind of a 2-stage thing, since both the gun and the projectile play their own parts in this. You should be able to set up the gun so that it can shoot any kind of projectile which meets certain criteria, and set up the projectile so that it meets some common interface or standard. Exactly how you do this is up to you- you have quite a few different options.
The gun needs to know a few things-
Given this information, I would then do something like this to acutally do the shot-
This will instantiate a prefab, and then send a message to the newly-created object telling it what direction to move in. Now, this message can be implemented any way you like- so you could have a rigidbody-controlled projectile, in which you would just set its velocity to the shootVector, or you could be using a transform.Translate-controlled one, which case you would do something different.
Now, the collision detection thing is another thing you need to look out for- to avoid the 'bullet through paper' problem, you need to do more than just rely on Rigidbody physics to manage everything for you. The way I do this, is using Physics.Linecast between the object's previous location, and its current location.
As for the optimisation problem, I wouldn't recommend adding lights to lots and lots of projectiles, but you can do that on key ones to draw the eye to them. Depending on the shader, you can do self-illuminated glowing textures, or particles- but in the end it really just comes down to testing. See how many bullets you can manage!
answered Nov 08 '11 at 07:37 AM