2D Toolkit Forum

2D Toolkit => Support => Topic started by: vambier on October 08, 2012, 09:50:51 pm

Title: Empty object with collider
Post by: vambier on October 08, 2012, 09:50:51 pm
I want to add an empty object(full alpha) to my player, this object must be able to collide with other objects. What is the best way to achieve this?
Title: Re: Empty object with collider
Post by: unikronsoftware on October 08, 2012, 10:16:39 pm
Just manually add a boxcollider, or add a gameobject child with a boxcollider & rigidbody. Both will work.
Title: Re: Empty object with collider
Post by: vambier on October 08, 2012, 10:28:13 pm
Can I also change the shape of that collider, or does it have to be a box?
Title: Re: Empty object with collider
Post by: unikronsoftware on October 08, 2012, 10:33:22 pm
That will need to be a box / sphere, otherwise you'll have to build your own meshes somehow. You shouldn't really be moving a polygon collider anyway, its not exactly cheap...
Title: Re: Empty object with collider
Post by: vambier on October 09, 2012, 09:43:53 am
Thanks, I don't know if it will cost that much in my game since I only have a couple of objects that have colliders at a time. But I'll see if I can make a custom mesh for this.
Title: Re: Empty object with collider
Post by: unikronsoftware on October 09, 2012, 10:27:22 am
You can also do it like this if you want -
Create an empty texture (0 alpha throughout)
Import into sprite collection
Draw polygon collider

The sprite will be optimized out as its empty so won't take up any space in your atlas.
Title: Re: Empty object with collider
Post by: vambier on October 09, 2012, 11:11:27 am
Yeah I tried that yesterday, but I got errors in unity(null reference if I remember correctly) when clicking "commit" in my spritecollection.
I just created a new sprite collection(also tried in an existing one), then added my full alpha sprite, turned on compression and set the collider to polygon.
Then I drew my polygon and wanted to click commit, and then I got the null reference error.
Title: Re: Empty object with collider
Post by: unikronsoftware on October 09, 2012, 11:14:09 am
You could add one pixel of 1 alpha... its probably complaining because its cropping the image fully - I thought it'd work with the padding, but clearly not.
Title: Re: Empty object with collider
Post by: vambier on October 10, 2012, 10:23:47 am
1 pixel alhpa helped! Thanks!