Hey all. It seems to me there is no way to have a collision or trigger called for two 2d rigidbodies without also having there positions changed by physics. I want to be able to manually move and overlap both object but have a function called when they overlap.
Collisions and triggers only work with the physics engine, but you can move objects manually (using functions like Translate) and it works fine. Just make sure at least one of the objects is non-kinematic.
–Eric
you can use Rigidbody2D.MovePosition to move them through the physics engine. This will simulate actual physics movement, taking into account colliders, etc. Remember that you need at least one rigidbody for a collision to take place.
This last part is the problem. Say I have 3 object, that each should be able to call the collision or trigger functions, but not push each other away with physics (so they can overlap). How would I do that?
The thing is, I do not want the physics to affect movement/position, only want the collision checking.
If you use triggers, there is no pushing away with physics. Objects only physically interact if they use non-trigger colliders.
–Eric
Ah, it seems if all objects are non kinematic triggers, I can achieve what I want
I move everything manually by directing updating the transform position. No rigidbodies on anything. Using raycast, boxcast, overlapping area etc all work fine. I tested a lot of ways to strip out the bulk and streamline this stuff. So… this is something to keep in mind. I know people say directly updating the transform position leads to poor performance but I have not seen that yet.
You may have misunderstood. The issue is when you have static colliders, and move those, because then the scene graph has to be rebuilt. If you move rigidbodies, they’re designed to be moved, so that’s not an issue.
–Eric
Yeah that is what I mean. I don’t use the rigidbodies anymore at all. I just stick colliders on the relevant game objects and move them by updating their transform.position. So far I have not seen issues from doing this although these are static colliders based on what I read (simply because they do not have rigidbodies on them). I will have to do some tests and see how much it can handle.But so far (in past projects) I have not seen any performance issues even with the screen filled with enemies and missiles. Maybe it effects 3D more than 2D.
If you’re getting the frame-rate you desire on the devices you want then sure, go ahead and do anything however, it’s a fact that moving 2D static colliders is much more expensive than colliders attached to a kinematic/dynamic rigid-body and to be honest, what’s the harm in adding a single Rigidbody2D component set to kinematic if it gives far better performance? More CPU time to do other stuff.