Hello Guest

Author Topic: Empty object with collider  (Read 6268 times)

vambier

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Empty object with collider
« 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Empty object with collider
« Reply #1 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.

vambier

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Empty object with collider
« Reply #2 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Empty object with collider
« Reply #3 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...

vambier

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Empty object with collider
« Reply #4 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Empty object with collider
« Reply #5 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.

vambier

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Empty object with collider
« Reply #6 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Empty object with collider
« Reply #7 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.

vambier

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Empty object with collider
« Reply #8 on: October 10, 2012, 10:23:47 am »
1 pixel alhpa helped! Thanks!