Circle hitboxes.

Hi there JGO!

I’ve plans for the combat-system, but I only need to have some sort of range to continue. I thought I would make a simple square hitbox, with 4 forloops:


http://img716.imageshack.us/img716/9259/womx.png

But as you probably can see is that the side of the square are closer to the center then the edges. So if anyone know a way to make a circle hitbox, it would be great.
I thought something of: x+y = range (20) and then looping through a forloop of them. I only have no idea how I am going to accomplish this. So I need your help, if you help me don’t post any code, as I need to learn from experiencing with my own ideas.

Thanks already!
-RoseSlayer

Why is your hitbox so big?

Its silly to have to change your collision algorithms just because you for some reason don’t have a smaller hitbox. Just use an AABB and check against the tiles, which will also have hitboxes.

The other way you could do it is just to check if the tiles around the player are “solid”, and if they aren’t you can move. I don’t recommend this way, however, because you can only check tiles, and the tiles will have to a uniform size with every other one. So you won’t be able to have half tiles or special items with hitboxes. Just use AABBs, which by the way do not require for loops for anything.

As a side question, is your game based off of vanZebans game?

I even don’t think I need a hitbox anymore, I could make a check like:

	public boolean inRange(){
		int xDifference = entityTarget.x - x;
		int yDifference = entityTarget.y - y;
		if(xDifference < 0)
			xDifference = -xDifference;
		if(yDifference <0)
			yDifference = -yDifference;
		if(xDifference + (yDifference - 3) <= range)
			return true;
		return false;
	}
}

It was a hitbox for combat, not for walking.
and your side question is true. (wich is kinda obvious didn’t changed character image :P).
-RoseSlayer

Hit boxes don’t need to be equal sided squares, they can be rectangles as well. You’re screenshot makes it look like the hit box is much larger than needed as Opiop mentioned. They can be any size including being a smaller size than the sprite they’re attached to. As for circular hit boxes, you’re just doing a check for anything within a certain diameter. You could probably use something like the Midpoint circle algorithm to determine which tiles need to be checked for collisions. Just a thought.

I’ve just found a possible answer,

Use Pythagoras’ theorem! A2 plus B2 = C2!

Have the point you are checking for check for the distance of x for ‘A’ and distance of y for ‘B’. if the square root of ‘C2’(also known as C) is less than or equal to the radius you are checking for, then the boundary has been reached! :smiley:

Haven’t actually tried this out, but I hope I’ve helped.

It was stupid of me to make a hitbox for combat, it will take alot of cpu to do a forloop or algorithm the whole time, a simple code to calculate the pixels between the entities is much better:

http://imageshack.us/a/img35/9022/c43.PNG

http://imageshack.us/a/img853/9297/llyx.png

These 2 pictures will show it is now a circle! (or is it a 45° turned square? :P)

-RoseSlayer

! THANKS, Now it is a real circle, not a rotate Square! :smiley:
Thanks for all the help guys, love the JGO!
-RoseSlayer

Can I see a pic of the new product? :stuck_out_tongue:

Hey, why couldnt a distance formula be used?

So whenever you try to attack or shoot or whatnot, for all objects in the game if their distance is less than [tolerance] then you hit that.

distance = Math.sqrt((x1 - x2)^2 + (y1 - y2)^2)

Is there somthing im not seeing?

Which product do you mean, the code or a screenshot of the game?

Screenshot I mean :stuck_out_tongue:

But code would be nice too, if you so desire.

I don’t have a for-loop so you cannot see the circle, I dont think I got time for making like random points around the character and draw the circle, currently working on items and armor:


http://img560.imageshack.us/img560/8917/gahf.png

Thanks for showing interest ^,^
-RoseSlayer