Forum

> > CS2D > Scripts > Rotate image with hitbox
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Rotate image with hitbox

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Rotate image with hitbox

Mami Tomoe
User Off Offline

Zitieren
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?

alt Re: Rotate image with hitbox

DC
Admin Off Offline

Zitieren
cs2d lua cmd imagehitzone hat geschrieben
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.

alt Re: Rotate image with hitbox

Mami Tomoe
User Off Offline

Zitieren
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?
1× editiert, zuletzt 21.01.19 20:54:56

alt Re: Rotate image with hitbox

DC
Admin Off Offline

Zitieren
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.
1× editiert, zuletzt 21.01.19 21:28:34

alt Re: Rotate image with hitbox

Mami Tomoe
User Off Offline

Zitieren
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?
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht