Hello Guest

Author Topic: Sphere collider ?  (Read 5851 times)

cs3d

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Sphere collider ?
« on: July 09, 2012, 09:19:23 pm »
Hi !
Is it possible to have a sphere collider in the Sprite ?
I have a ball but I can only do box collider with TK2D .
Do I have to do sphere colliders out of sprites then atach then to the colliders?
thank you !

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sphere collider ?
« Reply #1 on: July 09, 2012, 09:59:14 pm »
It isn't possible to create it directly in the interface - thats for historical reasons mainly. This will most likely be addressed in a future update.

The easiest way to do it now is to set the collider type to "Unset" (it won't interfere with what you set up) and then create a prefab of the sprite and attach a sphere collider like you would with any normal Unity component.

ScrewWorkn

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Sphere collider ?
« Reply #2 on: August 02, 2012, 03:55:13 pm »
I would also ask for the Sphere Collider.

Is there a simple way to calculate off the Sprite object what the Sphere radius should be based on the sprite?  I assume you do this in the background for the box collider.

Chris



unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sphere collider ?
« Reply #3 on: August 02, 2012, 06:18:14 pm »
Sphere colliders (and compound colliders) will come in a future update, but I'm currently concentrating on 1.80 with platform specific atlas loading.

You have all the sprite positions by accessing the spritedefinition sprite.GetCurrentSpriteDef().positions. The bounding boxes are precomputed at "Commit" time, so there isn't any runtime code that does any of this stuff, but the data is there for you to do it should you want to.

With the positions array, you can find the average position in the point cloud to find a sensible center point for your sphere, and then find max(abs(x),max(abs(y),abs(z))) from the center to find the largest radius.