Page 1 of 1

Collision - bitmap background

Posted: Thu Mar 12, 2009 11:25 pm
by mLaPL
please help me... :) i try but cant create good collision.

this is map from game, map is none object ( standard png image ) player hero image is png format 48x64. how create good collision for elements from image ?

this is map (1024x768)
Image

and this is first plan to hide hero to back (1024x768)
Image

Re: Collision - bitmap background

Posted: Fri Mar 13, 2009 5:34 am
by Illidane
I think you need to place rectangle shapes on your level, that hero may collide with it.

Re: Collision - bitmap background

Posted: Fri Mar 13, 2009 1:58 pm
by mLaPL
i try with rectangle and for me this is not what i need :/ the best way if can I use line collision.

i have problem with none horizontal and none vertical lines :/ like this on image.

i use to collision one center point from hero image.

Image

Re: Collision - bitmap background

Posted: Fri Mar 13, 2009 2:44 pm
by mLaPL
eureka... :) Collision - Point with any Line. For me this thopic is closed :) thx...

Code: Select all

function PointCollisionWithLine(x,y,x1,y1,x2,y2,tolerance)

        -- range from x,y to x1,y1
	a = x - x1
	b = y - y1
	c = (a*a) + (b*b)
	c1 = math.sqrt(c)
	
        -- range from x,y to x2,y2
	a = x - x2
	b = y - y2
	c = (a*a) + (b*b)
	c2 = math.sqrt(c)
	
        -- range from x1,y1 to x2,y2
	a = x1 - x2
	b = y1 - y2
	c = (a*a) + (b*b)
        c3 = math.sqrt(c)

       if (c1+c2)<=(c3+tolerance) then return true else return false end

end

Re: Collision - bitmap background

Posted: Sat Mar 14, 2009 5:10 am
by Skofo
Woo! ^^ You're pretty smart.

Re: Collision - bitmap background

Posted: Sat Mar 14, 2009 10:54 am
by mLaPL
thx...

good think for this is the same function but short.

if collision lines is constant then we not must calculate line range any time, we can use function like this:

Code: Select all

function PointCollisionWithLine2(x,y,x1,y1,x2,y2,line_range_with_tolerance)

        -- range from x,y to x1,y1
   a = x - x1
   b = y - y1
   c1 = math.sqrt((a*a) + (b*b))
   
        -- range from x,y to x2,y2
   a = x - x2
   b = y - y2
   c2 = math.sqrt((a*a) + (b*b))

       if (c1+c2)<=line_range_with_tolerance then return true else return false end

end