Rigid-body Trigger Help

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

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

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

Thanks in advance

Link to old Post: https://answers.unity.com/questions/155690/keep-rigidbody-awake.html?page=1&pageSize=5&sort=votes

There is something called “wake/sleep” modes for RigidBodies.
Perhaps you need to “Wake” the rigid body up.

1 Like

thanks for reply, but if it was asleep, why does it work 40% of the time, why not 0%

your right, I just need to Learn and apply this.

https://puu.sh/EDR6o/316f44ff5d.png

I tried this and it makes no difference, I put the wake up function in Update and also no go

https://docs.unity3d.com/ScriptReference/Rigidbody.WakeUp.html

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.

1 Like

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.

If you could tell us a bit more about what those 200 units actually are and what that 1 static object is, there could be better solution overall. : -)

Not 100% what you mean there is OverlapSphere for 3d and OverlapCircleAll for 2d.

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.

@Reedex @Baste

Thank you for reply, I made a Video explaining everything.

https://www.youtube.com/watch?v=GveRwJIazSw

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?

1 Like

Edit->Project Settings->Physics has a table where you can toggle on and off collisions between layers. Ours look like this:

5170979--513113--upload_2019-11-13_15-54-0.png

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.

1 Like

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

LOL

1 Like

What about the profiler?
Now that’s Window->Profiler and in there tick deep profile.

@Reedex @Baste

With The Grid Online

With The Grid Offline

I used these Collider Settings: Didn’t Make a noticeable difference

Hmm, may we see how you move the Rigidbodies?

  • not sure how that PlayerLoop thingie works, never seen that.