this is my first post here so bare with me. I am currently attempting to create a 3d bullet hell game. In this game i want to generate a lot of projectiles of varying sorts that are emitted from varying sources. I have tried using instantiate and destroy to create and kill physical (rigidbodied) bullets, but once I get a few sources on screen firing at once, I experience severe slow down. Any thought on how to fix this would be very appreciated!
You don't really need physics for a bullet hell game - they just travel in a straight line until they smack into something. I think you could save a LOT of processor time by making your own really basic behaviour to keep your bullets moving.
At the moment you'll be calculating all kinds of things you don't need. I'd say 'Keep It Simple'.
So store the Vector3 that is the direction and speed it was shot in, then simply multiply that every frame. So off the top of my head...
You'll also need to add collision detection of course, but this basic example SHOULD have you with a particle that keeps travelling in the direction it was fired and is MUCH less complex than a RigidBody.
answered Jan 23, 2012 at 04:53 AM
Don't use Instantiate at all if you can avoid it, and certainly not to instantiate bullets in a game of this type. Use an object pool script. There is one ObjectPool.cs, written by Invulse, that you can find on the forum and is free to use as is or modify. It goes in the "Plugins" folder, not "Scripts".
You just need to set the position and rotation of the object in the next line, and make sure you reset whatever needs to be reset on the bullet before calling PoolObject to dispose of it.
answered Mar 06, 2012 at 11:00 PM