Hello Guest

Author Topic: Pixel perfect collision detection  (Read 5239 times)

dm

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Pixel perfect collision detection
« on: August 23, 2013, 05:29:00 am »
Hi, i'm want to make a pixel perfect collision detection, so i have question.
I have 2 sprites "Gray" and "White", they collided each other as you can see in attachment.
Can i get pixels for each sprite in intersection? Actually i don't need RGBA, i need only alpha pixels.

Edit: These objects are tk2dSpriteAnimator.
« Last Edit: August 23, 2013, 05:38:49 am by dm »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Pixel perfect collision detection
« Reply #1 on: August 23, 2013, 10:55:57 am »
There isn't a way to do this out of the box.
You will have to read the texture to get this information -
Work out the position inside the intersection point, work out the UVs for this, and look up into the texture. The problem doing this is that Unity will make a copy of the texture as soon as you read from it, increasing memory overheads significantly.

dm

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Pixel perfect collision detection
« Reply #2 on: August 23, 2013, 11:52:06 am »
Thank you.
How i can read a texture from current frame of current animation?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Pixel perfect collision detection
« Reply #3 on: August 23, 2013, 12:37:59 pm »
sprite.CurrentSprite returns the current sprite definition.
You can then extract the positions, uvs, etc from there. You'd have to work out where in the sprite you clicked and find the corresponding UV.

dm

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Pixel perfect collision detection
« Reply #4 on: August 23, 2013, 12:47:52 pm »
Thank you.