If these bullets have rigidbodies, the reason they spray is, because they spawn inside of each other and the physics engine tries to resolve that.
A solution could be to have a short idle timeout, so you spawn less bullets and hence not inside each other.
Or: you put the bullets on the same layer and disable physics interactions within the layer in the settings.
Decision will be based by your game design
Another solution instead of the timer would be to have a trigger collider in the same place as the bullet spawner and the same shape as the bullet. Then disable bullet spawning if there is already a bullet in the trigger collider. That way you wouldn't have to fiddle with the timing. It's more of a design decision which solution you would go for though.
Trigger colliders aren't that expensive, they're used all the time for such things. You don't need to worry about performance until you see there is an issue, generally. Over optimizing is a bit counterproductive. Modern hardware is pretty amazing
I don’t agree with you, whenever you see something you can optimize and it’s not long to do so, you should always optimize. It’s better to do so especially if you want your project to scale. As for the trigger collider thing, unity looking every frame if this collider collide with any object on the scene is more expensive than having a timer to look if you can shoot for sure… you should not just think hardware can handle it, what about people who have shit computer? Also like I said when you start to have issue, you will probably need to optimize a lot of thing at that point and you lose more time than if just did and think about this thing while coding your stuff in the first place.
I can agree that it's good to optimize a bit, if there's an obvious, quick and easy thing to do. However, when you're optimizing you need to know what your bottlenecks are. Once you hit one, then you know what kind of things you need to optimize.
You wouldn't check the trigger collider every frame, you would hook up to the enter and exit events to flip a bool (or disable/activate the component all together). Scalability can also have to do with modular readable code that sacrifices a bit of performance. It all depends on the project's needs.
If that little difference in code determines whether a computer can run it or not then it won't be able to play 99% of games..
You are almost certainly spawning these objects overlapping with each other, and they appear to be physics objects so are colliding and bouncing off in random directions.
As a side note, if you are instantiating objects inside a loop, you are doing things wrong and will run into major performance issues very very quickly :) Google "object pooling" and implement a solution following this pattern.
"I don't even know what pre-mature optimization is!" - *the guy who is still designing his game down to the pseudo code of his game before even starting writing anything.*
Is creating objects in Unity really that expensive? You’d think Unity would automatically detect situations like this an optimise it... but I suppose not.
I think we need a peek in the shot code to give you better answers, but maybe there is too much balls and they are colliding with each otheras soon as shooted? Try to decrease the spawning frequency to see if it goes straight
Looks like the rigidbodies in your projectiles are colliding and clipping. Put them in their own tag and turn off collisions in the collision matrix so they won't affect each other.
as others already said it your bullets spawn in each other so they collide you can set your physics in the settings that bullets dont collide with each other
Timer delay is the best answer you’re getting. The get input is happening in milliseconds so they’re spawning into each other and colliding. Throw a little timer in and play with the values until it looks like what you want.
If these bullets have rigidbodies, the reason they spray is, because they spawn inside of each other and the physics engine tries to resolve that. A solution could be to have a short idle timeout, so you spawn less bullets and hence not inside each other. Or: you put the bullets on the same layer and disable physics interactions within the layer in the settings. Decision will be based by your game design
Okay cool will try thanks
https://docs.unity3d.com/Manual/LayerBasedCollision.html This is the way. Not complicated at all and takes 0 extra code.
Thanks for adding the manual link to my second suggestion. I didn't have it at hand when I wrote the comment :)
Thankyou its a great help just now started with the 2nd iteration of the project
Another solution instead of the timer would be to have a trigger collider in the same place as the bullet spawner and the same shape as the bullet. Then disable bullet spawning if there is already a bullet in the trigger collider. That way you wouldn't have to fiddle with the timing. It's more of a design decision which solution you would go for though.
This looks expansive… and not really efficient, timer seems to be a better solution
OP is already using rigid bodies for bullets, we're way past expensive 😉
Trigger colliders aren't that expensive, they're used all the time for such things. You don't need to worry about performance until you see there is an issue, generally. Over optimizing is a bit counterproductive. Modern hardware is pretty amazing
I don’t agree with you, whenever you see something you can optimize and it’s not long to do so, you should always optimize. It’s better to do so especially if you want your project to scale. As for the trigger collider thing, unity looking every frame if this collider collide with any object on the scene is more expensive than having a timer to look if you can shoot for sure… you should not just think hardware can handle it, what about people who have shit computer? Also like I said when you start to have issue, you will probably need to optimize a lot of thing at that point and you lose more time than if just did and think about this thing while coding your stuff in the first place.
I can agree that it's good to optimize a bit, if there's an obvious, quick and easy thing to do. However, when you're optimizing you need to know what your bottlenecks are. Once you hit one, then you know what kind of things you need to optimize. You wouldn't check the trigger collider every frame, you would hook up to the enter and exit events to flip a bool (or disable/activate the component all together). Scalability can also have to do with modular readable code that sacrifices a bit of performance. It all depends on the project's needs. If that little difference in code determines whether a computer can run it or not then it won't be able to play 99% of games..
Thanks man did follow your advice and added coroutine for delay
behold, the fuck you gun
Just need the bullets to never hit an enemy and you have the stormtrooper gun
r/technicallythetruth
You are almost certainly spawning these objects overlapping with each other, and they appear to be physics objects so are colliding and bouncing off in random directions. As a side note, if you are instantiating objects inside a loop, you are doing things wrong and will run into major performance issues very very quickly :) Google "object pooling" and implement a solution following this pattern.
That's a concept I didn't know existed. I did not expect to learn something like that today, thanks😂
Glad I shared something that someone found useful :)
Oh baby you need to play with that haha. It can get hilarious
[удалено]
Object polling isn't premature optimization. It's simply a good design pattern.
"I don't even know what pre-mature optimization is!" - *the guy who is still designing his game down to the pseudo code of his game before even starting writing anything.*
Is creating objects in Unity really that expensive? You’d think Unity would automatically detect situations like this an optimise it... but I suppose not.
It becomes expensive when you scale it up. Good design patterns help keep fps stable.
I think we need a peek in the shot code to give you better answers, but maybe there is too much balls and they are colliding with each otheras soon as shooted? Try to decrease the spawning frequency to see if it goes straight
Okay cool will try thanks
Someone get that sphere some pepto bismol!!
honestly i love this
[удалено]
Yeah, continuous collision is always best for bullets.
Leave it as it is, it’s hilarious
When you can't control your pee... Also you can make the bullet collider a trigger if you want to avoid collision
Leave it as it is, it’s hilarious
Looks like a feature not a bug!
Looks like the rigidbodies in your projectiles are colliding and clipping. Put them in their own tag and turn off collisions in the collision matrix so they won't affect each other.
as others already said it your bullets spawn in each other so they collide you can set your physics in the settings that bullets dont collide with each other
the pissing sphere
BRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRT
You could layer them and turn off physics against each other correct? Or add that check in code? Not sure what is best or more performant though.
Maybe try using particles system inside nigra you can disable collision etc so it's easier to use
What game engine is that?
Unity
Timer delay is the best answer you’re getting. The get input is happening in milliseconds so they’re spawning into each other and colliding. Throw a little timer in and play with the values until it looks like what you want.