- Home /
Effectors not working with compound collider?
I have a problem with the Area Effector 2D and my compound colliders. The thing is that the effector is applying its force multiple times to the Rigidbody2D. So objects containing multiple colliders are effectively affected by much stronger forces. This behaviour seems kind of strange to me... Is there any way to tell the effector to apply its force once per rigidbody instead of once per collider? Thanks!
Answer by MelvMay · Dec 27, 2015 at 01:07 PM
Why is it strange; because it's not what you want? Have you looked at any of the properties and tried experimenting?
Try changing ForceTarget i.e. the target where the effector applies the force. You can set it to affect the collider or the rigid-body. Both have use-cases.
Answer by DLBit · Dec 28, 2015 at 12:04 PM
Exactly... :-) And it's not what the documentation tells me.Why is it strange; because it's not what you want?
Don't know if I tried everything but I experimented with a lot of the properties and combinations of the composition of my objects affected by the effector.
ForceTarget tells something about where the force is applied not how often.
Manual:
The force target is the point on a target object where the effector applies any force.
Scripting Reference:
The target for where the effector applies any force.
If I have an Object with a single collider attached everything works fine. If I split the collider (e.g. two half sized boxes instead of the single one) the effector applies its force twice. The GameObject I want to use has a compound of four colliders. This means my object is affected by the force four times in a single FixedUpdate. That is my problem with Unity's AreaEffector2D and I don' know how to handle it.
Currently I implemented my own Area Effectors to handle this.
If you want the force applied once then set the target to Rigidbody2D (there is only ever one rigidbody). This won't produce rotational forces though as the force is always applied to the center of mass but if you don't want that then this will work.
When set to collider, the force you specify is applied to the center of the collider that is in contact (not all colliders on a RB will necessarily be in contact) and I can see how that might be a problem.
The only conceivable way to do this is during the fixed-update, the effector counts how many colliders on the RB are touching, find their common center-of-mass and apply the force there.
It's certainly a feature that could be added.
If you want the force applied once then set the target to Rigidbody2D (there is only ever one rigidbody).
Exactly this is the problem. What you describe is what should be, but it's not. There is the one and only Rigidbody2D but multiple colliders. Each collider of the compound triggers the AreaEffector2D which then generates as many forces as there are colliders. All the forces are then applied to the one Rigidbody2D resulting in a force with a magnitude of N times that force with N the number of the colliders in the compound.
Here is a $$anonymous$$imalistic sample.
It contains two objects, each with a single Rigidbody2D. One has a single collider attached and the other four of them, each one fourth in size. Both objects are located inside an AreaEffector2D which adds a force upwards. If the AreaEffector2D would work as expected, both objects should behave exactly the same. But they don't. Regardless to the settings in the AreaEffector2D (ForceTarget: Rigidbody/Collider) or the objects (Rigidbody2D, UseAuto$$anonymous$$ass: true/false). The object with the compound collider receives always a much larger force (in this case four times as large).
I have now implemented my own version of the effector which handles that correctly and does other magic besides this. I'm now happy with that. :-)
This has been fixed. It is under review and will be going into the release streams in the near future.
Your answer
Follow this Question
Related Questions
Is this a correct way to have multiple different compound colliders in one gameobject? 1 Answer
Physics2D.OverlapBoxNonAlloc not return all overlapped collider 1 Answer
2D Raycasts Only Work in Certain Directions 0 Answers
Physics2D.Linecast ignoring walls 1 Answer
Is Overlap Circle Supposed to return inactive colliders? 1 Answer