This site requires JavaScript, please enable it in your browser!
Greenfoot back
Dillybar
Dillybar wrote ...

2015/1/5

Making a square hitbox

Dillybar Dillybar

2015/1/5

#
I was hoping someone would be able to help me with creating a square hitbox for my character rather than just using the image width, as the bottom is much smaller than the top (Or if there is a possible way around this in coding - It is for platforms below the actor and I use the getoneobjectatoffset command). Any input would be appreciated
danpost danpost

2015/1/5

#
Oftentimes, there is a 'trick' that can be used as a way around something. In this case, it may just be temporarily replacing the image with one that has the width of the bottom before checking for intersecting objects, then immediately restoring the original image. If the bottom of the image is not exactly in the center, you may also have to move the actor slightly and then immediately relocate it back after checking for intersecting objects.
erdelf erdelf

2015/1/5

#
maybe you could use the pixel perfect collision detection by bush2207
Dillybar Dillybar

2015/1/5

#
So, If I just drew a nearly transparent box around the character would that work? Or do the pixels have to be solid for the code to work properly?
danpost danpost

2015/1/5

#
For the pixel perfect collision detection class to work, the non-transparent pixels of the images are dealt with. For the 'trick' to work, the transparency is not dealt with at all -- only the extent of the image.
Dillybar Dillybar

2015/1/5

#
ok so, just to clarify, transparent pixels are only recognized if I use the pixel perfect collision detection?
danpost danpost

2015/1/5

#
Dillybar wrote...
ok so, just to clarify, transparent pixels are only recognized if I use the pixel perfect collision detection?
A better way to put it is that the with normal collision detection, only the existence of a pixel is important; with pixel perfect collision detection, the state of the pixels become a factor.
Dillybar Dillybar

2015/1/6

#
Lol ok, so then with a normal collision detection, I could draw a transparent box around mario to create a square hitbox?
danpost danpost

2015/1/6

#
If you mean like taking an exaggeratedly large square transparent image and drawing Mario in the middle of it and then setting that image to a Mario object, then yes. All images are rectangular to begin with, regardless of where the actual color portions within that image are, however, and since normal collision detection uses the extent of the image, not the color portions within it, the hitbox is already rectangular. Most people have problems with the image itself being larger than the color portion within it and want the image size to be reduced without reducing the size of the color portion within it. In other words, they want to strip off all outer rows and columns of pixels that are completely transparent so that the 'hitbox' is at its minimal size.
You need to login to post a reply.