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!
that's "bear" with me. not "bare".
it's the same word as "bearing a load" or "ball bearing".
Just click "Edit" to fix !
Damn spelling nazi! Done :P
Answer by IgnoranceIsBliss
Jan 23, 2012 at 04:53 AM
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...
public Vector3 Velocity;
transform.Translate(Velocity * Time.deltaTime);
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.
This boosted my fps DRAMATICALLY! THANKS!
Answer by Kiloblargh
Mar 06, 2012 at 11:00 PM
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.
Totally agree. I am not sure if this script happens to disable the object, but if you disable them when you add them back in the pool it prevents any unnecessary update calls to those game objects.
Answer by potatoking
Dec 30, 2013 at 09:04 PM
You could also use particle systems instead of instantiating objects
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
8 People are following this question.
Bullet always facing the sky.
Getting an error every time I try and access an Instantiated objects methods.
Bullet Spawning Problem
!!!!!bullet fires only on the left never straight!!!!!!!
make bullet move forward.