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.

  1. 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.
  2. similarly can see action in slow motion adjusting time scale. time.timescale = 0.1f;

to prevent this,

  1. you may want @ continuous collision though i've failed use in unity.
  2. you may want utilize more physics layers. http://docs.unity3d.com/manual/layerbasedcollision.html
  3. you may want detect collisions using raycasts.
  4. you can enlarge shield , reduce weapon swing speed or bullet speed. it's impossible penetrate through shield.
  5. you can decrease period of fixedupdate calculations weapon movement smoother , there less penetrations. http://docs.unity3d.com/manual/class-timemanager.html
  6. 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.
  7. 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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -