If all of that fails PM me with your project and i can take a look monday after the holidays. I hate putting that sort of debugging on you the user but since its almost christmas i want you to have something else to look into. It might have just been a ordering logic issue. ![]() If you object is part of the list but it still seems to be the one not getting the call then try pulling my new eventSystem ordering repo ( ) and see if that fixes it. it required to enter the difference in Z position from. Try changing the call to be the RaycastAll instead. This question is a bit old, but I was looking for a a way to get a GameObject with a mouse click in unity 2D, and the Answer from Esa almost helped me, but I couldn't afford to make it to work, so with a bit of research I saw that was returning the center of the screen area of the Camera and to it work right. I'd debug.log the "hits" list to see if the tavern object is even part of it or not. Who knows maybe doing GetRayIntersectionAll doesn't work perfectly or something. If that doesn't work, try pulling the source code ( ) and play around with modifying the Physics2DRaycaster. If they are the same any change the camera isn't the same (i know you've said you attached it to the main camera but just a thought). Make sure that your tavern is set to a layer that the Physics 2D Raycaster can hit. mousePosition) the same position as what the EventSystem thinks the mouse position is? (debug log that value out / select the EventSystem GO and look at the inspector for the information). Might also be worth pointing out that eveything else works in that area, so if for example i want to build a tower there, i have no problem in building it, just i can't select it after! I am going stupid in trying to figure out the problem, any idea? When I zoom in (just changing the size of the camera and the x,y position in case, but not the distance from the scene) then, as in this picture here, i see that the area of "non raycasting" shrinks more and more until almost disappearing. The tavern (small building between trees on upper left) and whatever other building i decide to build in that upper part don't react to the raycaster and i always receive the message that i am hitting the terrain on click.Īt the same level of zoom, if they are anywhere else in the map they cause no problem. When the camera (ortographic, planes all correct so that the are fits in) is zoomed out (size 340 and a bit less) as in this first picture. My objects in the scene have a 2D collider attached and a script implementing IPointerClickHandler. In other words, use the ray-intersection calls to find RaycastHit2D(s) in 3D space for 2D colliders.I have a weird behavior with the Physics2DRaycaster attached to my main camera. This will also calculate an appropriate hit normal. All returned colliders are sorted based upon the direction of the ray along the Z axis i.e. Internally what these calls do are project the ray start/end points into the Box 2D collider space, perform a standard line-cast in 2D space to find which 2D colliders are hit then calculate using back-projection where on those colliders the ray intersects given the transform Z of the GameObject. Note that these calls will purposely return nothing if your ray is cast along the X/Y plane itself as 2D colliders are infinitely thin so you must always cast your ray along the Z axis at some angle. These calls are "GetRayIntersection", "GetRayIntersectionAll" and "GetRayIntersectionNonAlloc" and do what the say, find an intersection of a 3D ray on a 2D collider. ![]() ![]() There is however specialized calls that do take a Ray type for people that want to use 2D colliders in a pseudo 3D context. Raycast/Linecast for 2D take Vector2 not Vector3 because they operate along the X/Y plane only as it's 2D physics not 3D.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |