2D Toolkit Forum
2D Toolkit => Support => Topic started by: regnared on January 09, 2013, 09:20:40 pm
-
I know this question is not really related to 2D Toolkit, but is there a way to "know" which side of a box collider from a 2D sprite that was hit (top, bottom, right, left)? Since this is really basic stuff for everything, I would suspect it would be much easier to figure out. :o Maybe there's a function in 2DToolkit that gives you the information about the sprite?
Been looking everywhere to find an answer but it can't seem to find it. Would it be better to just go with raycasting?
(https://dl.dropbox.com/u/16537765/2d_toolkit/2d_toolkit_box_collider_sides.jpg)
-
In OnCollisionEnter, get the contacts, and look at the normal. You can work out the direction relative to your object that way. Having said that you might have more than one contact in which case you'd have to work out which one affected the impact the most...
-
That is what I was thinking. Big thank you. :)
-
If anyone finds this question, I was able to use raycasting for my problem. I posted a script and video here if you are curious.
Youtube Link - [ link (http://www.youtube.com/watch?v=gvKYJK9-ODw&feature=youtu.be) ]
Script Link - [ link (https://github.com/PhilippeChabot/Misc_UnityScripts/blob/master/2D%20BoxRaycasting%20C%23) ]