How am I supposed to know what new hitzone to call according to the new rotation?
Forum
CS2D Scripts Rotate image with hitboxRotate image with hitbox
6 replies 1
How am I supposed to know what new hitzone to call according to the new rotation?
imagehitzone has written
Attention: The hit zone is always rectangular. Image rotation does not affect the hit zone unless you change it manually!
This is maybe a bit misleading. I'll adjust the text, sorry.
What I wanted to say with this is that the rotation does not affect the hit zone AT ALL. The only way to change the hit zone is by changing the hitzone (offset and/or size) manually.
Hit zones are always a rectangle without any rotation in CS2D.
EDIT:
This is the image:
This image rotates towards the player (head first).
I want only the head of it to be able to be attacked but the hitzone is complicated for me because I've only started using it recently.
Is there a simple way to make only the head as a hitzone and allow the hitzone to rotate with the head?
edited 1×, last 21.01.19 08:54:56 pm
Edit: Actually the image has already the right size for that fix. You just have to move the visible pixels to the upper half so the head is in the middle.
More advanced fix: Recalculate and reset the hitzone position (offsets) manually based on the rotation. This is more expensive though because setting the hitbox so frequently causes additional traffic. And of course it's also a bit more complicated because you need to calculate it with sin and cos.
If you go for this approach I would store the rotation the hitzone was last changed to in a variable and only change it again when the rotation changed more than like 5° (or whatever value works fine). This optimization only makes sense when the rotation is quite slow. It won't make a difference when it's faster (per frame) than that 5° value.
edited 1×, last 21.01.19 09:28:34 pm
Placing the head in the center would just make the tail be the thing looking at the player...
And I'm not good enough at math to know how to use cos/sin for that other advanched fix.
Does anyone know the formula?
The hitbox only works right when the body is looking straight down because it doesnt care about rotation.
1