unity3d - Make two physics objects not collide but do detect collisions in Unity -
i have unity project in there 2d game world consists of static colliders make geometry solid characters inhabit it. player dynamic collider (with non-kinematic rigidbody). there's enemy character dynamic collider. both characters walk on floor , bump walls i'd expect them to.
what want achieve player , enemy not solid each other, can move through each other. achieved putting enemy , player on separate layers , setting collision matrix these layers not collide each other. problem i'm having now, however, want detect whether or not enemy , player ran each other. added trigger collider enemy character, it's on enemy layer means doesn't detect collisions player.
i thought of making sub-gameobject enemy, put on player's layer, add rigidbody , trigger collider , use detect collisions between player , enemy, feels convoluted leaves me wondering if there isn't more elegant solution this.
yes, need create child gameobject
, trigger collider, , put in layer interacts player layer.
no, don't need add rigidbody
new gameobject
, parent's rigidbody makes dynamic collider, ontrigger
events.
as side note, keep things organized, if create child of enemy don't put in player layer. example, in future might need disable player's layer collision itself. furthermore, if player interacts way many objects, i'd put single trigger on player instead of enemies, on separate playertrigger
layer, keep things simple.
isn't there simpler way? not really. definetly need non-interaction between player , enemy colliders, kind of interaction between them too. 1 of them needs span 2 layers, or whole interaction described single bool. physics engine processes lots of information in 1 go, can set layers , collisions want, during physics loop have no further control on happens. can't tell engine ignore collisions between 2 objects. having 32 layers, , having them behave in rigid way heavy optimizations. if concerned performance creating layer, disable interaction between layers don't need, trigger layer , floor , walls, or layers don't touch.
your alternative doing code, less elegant. single child capsule on player doesn't sound bad now, doesn't it?
Comments
Post a Comment