2D Toolkit Forum
2D Toolkit => Support => Topic started by: cs3d 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 !
-
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.
-
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
-
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.