Hi guys, So I am in a Situation where I have 200 units that need to trigger another Object based on proximity (I use on trigger Enter for this).
now there are two way so far that I can make this work
Give the 200 units a rigid-body (which is very taxing even if its kinematic but the trigger always works even if the FPS drops to 10.
Have the Rigid Body on the Static Object, this Increases my fps from 10 to 120, however, the trigger is very unreliable, it only detects around 40% of the collisions.
there was a very old post about this but It doesn’t really answer my questions and some of the suggestions have been deprecated.
is any of your objects moving very fast? Alternatively(depending on what you actually do)
you could try Physics.OverlapSphere for 3d or Physics2DOverlapCircleAll for 2d put onto the static object and yeah call it every frame (you can set layers as a parameter), but like i said it kinda depends on what you’re making.
thx for reply, I tried that, but I cant rotate the 2D by the x,plane, this is for an rts game. if I can lay the 2D collier on the xz plane that may work.
Anyway, I am giving up on this approach, At least I learned something. I will have to go back to making huge list and now I have to learn Multi-threading to get around how taxing RigidBodies are.
Moving 200 rigibodies around should be trivial. Use the inspector to find out what’s happening.
You probably want to set up the layer collisions so that the 200 objects are on a layer that doesn’t collide with itself, but collides with the layer of the proximity object.
Agreed, i had that in tower defense where there was a turret with 30 pellets as projectiles and it lagged each time it shot,
i wondered so i logged and it was 900 collisions right when they spawned at the barrel. Though i just added a bit of an offset so each spawned slightly at different position infront of the barrel.
how do I do that? I usually just use if functions in my scripts based on which layer the trigger had. but I dont know how to prevent the trigger in the first place with layers that are not of interest.
and if you use profiler, set it to deep Profile,
make it to the point the game is about 30 frames, and check what’s taking up most resources,what do you see?
Edit->Project Settings->Physics has a table where you can toggle on and off collisions between layers. Ours look like this:
Also, @Reedex is correct. I didn’t mean to write “use the inspector to find out what’s happening”; I meant “use the profiler to find out what’s happening”. My bad.
I knew what you meant when you said Inspector, and thanks you so much about this brand new information! holy crap I think this is going to make a huge difference, let me try it