Page 1 of 1

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

Posted: Wed Mar 18, 2020 12:12 am
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.

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

Posted: Wed Mar 18, 2020 1:29 am
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.

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

Posted: Wed Mar 18, 2020 5:15 pm
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.

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

Posted: Sat Mar 21, 2020 6:18 am
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.

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

Posted: Fri Apr 10, 2020 9:00 pm
by Smit1h
Boxes can also be decomposed into a triangle mesh and integrated with the world model.