unity3d - How to restrict which colliders are triggered? -
sorry if similar questions have been asked.
i have character can hold shield block incoming damage. character has circle collider body space. shield has box collider blocks off portion of whatever direction he's facing, , it's enabled when player holding down button. enemies have weapons surrounded triggered box colliders enabled when decide attack.
so, problem when character attacked while shielding, body collider detected , shield collider detected. can't find consistency no matter try.
[screenshots] (http://i.imgur.com/vhujbcg.png)
[code] https://gist.github.com/siketh/2401454977d10ed7699b
i've been struggling day , need set of eyes. isn't serious project if need see else i'm happy post more code or explain more of design.
it's because weapon intersects both character , shield @ same time. there great tools in unity if want see if that's case.
- notice unity has "play", "pause" , "play 1 step" buttons @ top of editor window. can pause game
debug.break();
instantly @ moment player fires or swings weapon. can watch what's happening step step. select character, shield , weapon can see colliders in action. way can see collides step step. - similarly can see action in slow motion adjusting time scale.
time.timescale = 0.1f;
to prevent this,
- you may want @
continuous collision
though i've failed use in unity. - you may want utilize more physics layers. http://docs.unity3d.com/manual/layerbasedcollision.html
- you may want detect collisions using raycasts.
- you can enlarge shield , reduce weapon swing speed or bullet speed. it's impossible penetrate through shield.
- you can decrease period of fixedupdate calculations weapon movement smoother , there less penetrations. http://docs.unity3d.com/manual/class-timemanager.html
- there high probability detecting both weapon-to-shield , weapon-to-player collision in 1 step. why not postpone decision 1 fixedupdate later. can check if there weapon-to-player collision or both collisions. if weapon-to-shield collision detected in previous update, know player hit shield no matter if weapon passed through shield or not.
- let's there no way can detect if weapon hits shield or player. using simple geometry, can check if attack coming direction of shield or not.
good luck :)
Comments
Post a Comment