Page 3 of 3

Re: ISO

Posted: Sat Feb 18, 2012 8:44 pm
by MarekkPie
Maybe something more like this? (It's just a snippet, no example, but HC provides collisions for arbitrarily shaped polygons, so I made a long hexagon.)

Code: Select all

function makeGroundingBound(obj)
        local r = obj.h / 4
        return HC:addPolygon(
                obj.x - r, obj.y + obj.h,
                obj.x, obj.y + obj.h - r,
                obj.x + obj.w, obj.y + obj.h - r,
                obj.x + obj.w + r, obj.y + obj.h,
                obj.x + obj.w, obj.y + obj.h + r,
                obj.x, obj.y + r)
end
EDIT:

Just tried to implement this into my little demo and am getting errors from HardonCollider.

Code: Select all


Error: ./HardonCollider/polygon.lua:329: attempt to call method 'isConvex' (a nil value)
stack traceback:
	./HardonCollider/polygon.lua:329: in function 'splitConvex'
	./HardonCollider/shapes.lua:115: in function 'construct'
	./HardonCollider/class.lua:93: in function <./HardonCollider/class.lua:90>
	(tail call): ?
	(tail call): ?
	[string "HardonCollider/init.lua"]:129: in function <[string "HardonCollider/init.lua"]:128>
	(tail call): ?
	[string "main.lua"]:22: in function 'load'
	[string "boot.lua"]:310: in function <[string "boot.lua"]:308>
	[C]: in function 'xpcall'

Re: ISO

Posted: Sat Feb 18, 2012 11:04 pm
by Camoy
Ah ha! That looks much more accurate. I've also gotten it to work in ISO.
Y6Kf3.png
Y6Kf3.png (9.58 KiB) Viewed 484 times
That is the resulting collision polygon.

Re: ISO

Posted: Sat Feb 18, 2012 11:27 pm
by MarekkPie
Glad that works for you. You might want to keep the actual collision polygon hidden and use something a little more aesthetically pleasing as its representation.

The gray represents the actual grounding bound; the yellow represents the visual bounding ellipse.

Re: ISO

Posted: Sat Feb 18, 2012 11:30 pm
by Camoy
I only enabled the collision polygons visibility for a demonstration. If you actually use Sprites, the collision polygons are invisibile.

Re: ISO

Posted: Sat Feb 18, 2012 11:33 pm
by MarekkPie
I think I still would give some representation, though. Imagine someone plugs this into an RTS. The usual way to show that a particular unit is selected is through a circle like this. Perhaps if you don't want to make it visible for all cases you have a simple boolean trigger that tells the shape handler whether to draw these or not.

Re: ISO

Posted: Sat Feb 18, 2012 11:44 pm
by Camoy
Optional representation allowed through sprite.setUpdate.

Code: Select all

sprite:setUpdate(function(shape)
    love.graphics.setColor(255, 0, 0)
    shape:draw 'fill'
    love.graphics.setColor(255, 255, 255)
end)
This will create a red collision polygon under the sprite. This allows for full customization of the collision box.