Forum

> > CS2D > Scripts > Rotate image with hitbox
Forums overviewCS2D overview Scripts overviewLog in to reply

English Rotate image with hitbox

6 replies
To the start Previous 1 Next To the start

old Rotate image with hitbox

Mami Tomoe
User Off Offline

Quote
Hi I have an image with its own hitzone configured but when I rotate the image the hitzone does not follow it, as the website claims.

How am I supposed to know what new hitzone to call according to the new rotation?

old Re: Rotate image with hitbox

DC
Admin Off Offline

Quote
cs2d lua cmd 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.

old Re: Rotate image with hitbox

Mami Tomoe
User Off Offline

Quote
Is there an easy way to rotate the hitzone? Or at least make it half-decent?


EDIT:


This is the image:
IMG:https://i.imgur.com/G6Jrcmz.png

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

old Re: Rotate image with hitbox

DC
Admin Off Offline

Quote
Easy (but kind of dirty) fix: You could make the image twice the size so the head is in the center of the image. Then you could just keep the hitzone in the center of the image as well. This would however would also let the whole rotation look differently though.

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

old Re: Rotate image with hitbox

Mami Tomoe
User Off Offline

Quote
The thing is the image is already twice it's own size with the end of the tail at the center so when I rotate the image the tail is the starting point.

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?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview