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):
And make that the white is path to be followed and the black is the hitbox that the objects would interact as a wall.
Is it possible to create a hitbox path from an image?
Re: Is it possible to create a hitbox path from an image?
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?
I see, thanks. ImageData:getPixel may be enough for me right now, I hope.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.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Is it possible to create a hitbox path from an image?
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?
Boxes can also be decomposed into a triangle mesh and integrated with the world model.
Who is online
Users browsing this forum: No registered users and 8 guests