Hello Guest

Author Topic: tk2dUI woking with 2D physics  (Read 5619 times)

lassade

  • Newbie
  • *
  • Posts: 1
    • View Profile
tk2dUI woking with 2D physics
« on: December 24, 2013, 02:53:13 pm »
I got some of the UI working with the new unity 2D physics, all i did was add the code below to the RaycastForUIItem method in tk2dUIManager script inside the for loop

Code: [Select]
Collider2D c = Physics2D.OverlapPoint (ray.origin, currCamera.FilteredMask);
if (c != null)
{
return c.GetComponent<tk2dUIItem>();
}

if you chose to comment the 3D physics part, you can also get the mouse point using

Code: [Select]
Vector2 mouseWorldPosition = currCamera.HostCamera.ScreenToWorldPoint (screenPos);
NOTE: 2D colliders closer to the camera will be triggered first

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dUI woking with 2D physics
« Reply #1 on: December 26, 2013, 12:25:33 pm »
Thanks for sharing the code :)

Thats more or less it - the raycast is pretty much isolated to one place and 2D collisions can be added really easily - we've don't support that internally because of some of the possible edge cases that can occur with 3D + 2D colliders with overlaps and layer.

coshea

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: tk2dUI woking with 2D physics
« Reply #2 on: January 30, 2014, 11:32:37 am »

I'm making a 2d game so want to use 2d physics, so only want to use 2d colliders. I'm worried if I make this change to tk2d then when I update later it will get overwritten, plus if I ever want to use it with a 3d game it would be broken.

I noticed in sprite collection generation, if you use 2d physics it makes a 2d collider, but when it comes to mouse/touch interaction you can only use 3d colliders. This took me a while to realise and is a little confusing.

Would be amazing to have a toggle option to 'only use 2d colliders' in future, if you wish.

All the best

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dUI woking with 2D physics
« Reply #3 on: January 30, 2014, 12:22:13 pm »
The plan was to move away from colliders with tk2d UI and use a custom collision detection system, but thats up in the air at the moment. tk2dUI doesn't use the tk2d sprite colliders as it uses the collider attached to the UIItem component, so they have to be done manually. I'll update when we've made up our minds about the direction there. For the immediate future though, we don't intend on changing it to support both 2D and 3D colliders because of the impracticality of changing all the prefabs.