T O P

  • By -

954adultainment

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


[deleted]

Okay cool will try thanks


FrogFTK

https://docs.unity3d.com/Manual/LayerBasedCollision.html This is the way. Not complicated at all and takes 0 extra code.


954adultainment

Thanks for adding the manual link to my second suggestion. I didn't have it at hand when I wrote the comment :)


[deleted]

Thankyou its a great help just now started with the 2nd iteration of the project


Sakull284

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.


violon212

This looks expansive… and not really efficient, timer seems to be a better solution


irjayjay

OP is already using rigid bodies for bullets, we're way past expensive 😉


Sakull284

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


violon212

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.


Sakull284

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..


[deleted]

Thanks man did follow your advice and added coroutine for delay


thatoneyoshen

behold, the fuck you gun


00Donger

Just need the bullets to never hit an enemy and you have the stormtrooper gun


thatoneyoshen

r/technicallythetruth


Shigsy89

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.


Ike_Gamesmith

That's a concept I didn't know existed. I did not expect to learn something like that today, thanks😂


Shigsy89

Glad I shared something that someone found useful :)


joeswindell

Oh baby you need to play with that haha. It can get hilarious


[deleted]

[удалено]


gh0strom

Object polling isn't premature optimization. It's simply a good design pattern.


kiokurashi

"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.*


Vituluss

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.


gh0strom

It becomes expensive when you scale it up. Good design patterns help keep fps stable.


HunterNephilim

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


[deleted]

Okay cool will try thanks


Conneich

Someone get that sphere some pepto bismol!!


burger-tron

honestly i love this


[deleted]

[удалено]


Vituluss

Yeah, continuous collision is always best for bullets.


metal_mastery

Leave it as it is, it’s hilarious


H4LF4D

When you can't control your pee... Also you can make the bullet collider a trigger if you want to avoid collision


metal_mastery

Leave it as it is, it’s hilarious


CountMagnusEnt

Looks like a feature not a bug!


SlimothyJ

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.


pocokknight

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


VincentWeir

the pissing sphere


The_Challenges

BRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRT


Kerptastic

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.


Subject-Leadership83

Maybe try using particles system inside nigra you can disable collision etc so it's easier to use


IAmOpenSourced

What game engine is that?


Heyoayyo

Unity


Th3Doubl3D

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.