Is it possible to create a hitbox path from an image?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
cazura
Prole
Posts: 14
Joined: Fri Jan 03, 2020 4:17 pm
Location: Brazil

Is it possible to create a hitbox path from an image?

Post by cazura »

Hello!

I'm working in a little project and it works basically like a very simple 2d top-down racing game.

In a racing game you have the circuit to follow. With my basic knowledge of hitboxes, I can only think about making the circuit as a flat image, and fill it with circles and boxes of hitbox. Now, this seems rather annoying and timing consuming. There is a better way to do it? I want to basic take a black-white image like that (But of course, with more complex circuits than this):

Image

And make that the white is path to be followed and the black is the hitbox that the objects would interact as a wall.
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Is it possible to create a hitbox path from an image?

Post by pgimeno »

You can read images, see ImageData:getPixel. If you just want to detect crashes, you can check if any of the four corners is in the black area of an image. For other physics effects like bouncing against the black area, things get more difficult.
cazura
Prole
Posts: 14
Joined: Fri Jan 03, 2020 4:17 pm
Location: Brazil

Re: Is it possible to create a hitbox path from an image?

Post by cazura »

pgimeno wrote: Wed Mar 18, 2020 1:29 am You can read images, see ImageData:getPixel. If you just want to detect crashes, you can check if any of the four corners is in the black area of an image. For other physics effects like bouncing against the black area, things get more difficult.
I see, thanks. ImageData:getPixel may be enough for me right now, I hope.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Is it possible to create a hitbox path from an image?

Post by bobbyjones »

Since there is a sharp color change between the white and black you write a simple edge detection algorithm and use that to convert the image to edges. You can then use those edges to create polygons. You can preprocess it so that it doesn't have to be done at run time. Once you have the polygons or lines or whatever it ends up being you can then use your favorite collision library.
Smit1h
Prole
Posts: 2
Joined: Tue Mar 03, 2020 10:07 am

Re: Is it possible to create a hitbox path from an image?

Post by Smit1h »

Boxes can also be decomposed into a triangle mesh and integrated with the world model.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests