ISO

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: ISO

Post 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'
Attachments
shadow.png
shadow.png (508 Bytes) Viewed 2432 times
User avatar
Camoy
Prole
Posts: 17
Joined: Fri May 06, 2011 8:03 pm

Re: ISO

Post 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 482 times
That is the resulting collision polygon.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: ISO

Post 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.
Attachments
shadow.png
shadow.png (1.74 KiB) Viewed 2421 times
User avatar
Camoy
Prole
Posts: 17
Joined: Fri May 06, 2011 8:03 pm

Re: ISO

Post by Camoy »

I only enabled the collision polygons visibility for a demonstration. If you actually use Sprites, the collision polygons are invisibile.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: ISO

Post 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.
User avatar
Camoy
Prole
Posts: 17
Joined: Fri May 06, 2011 8:03 pm

Re: ISO

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot] and 1 guest