K
K
Konstantin Mishachenko2015-03-13 16:29:19
Mathematics
Konstantin Mishachenko, 2015-03-13 16:29:19

Does the problem of rotating a sprite depending on the coordinate axes of movement have a solution?

I want to write a universal function for the dependence of the rotation of the character sprite on the value of the control axes.
Namely:
We have two axes:
X (horizontal) and Y (vertical), respectively,
The angle of rotation of the sprite depends on the coordinates (see figure) 02eed20104a14b42971383b355280c89.JPG
According to these data, I picked up a functional dependence, but it works only in 50% of cases (at zero points)
e5e2d929f916438086dee60f942ba052.JPG
The resulting function in EXEL looks like:
=ABS(((A2+2)*-90)*A2)+ABS(((B2*90)-90)*-1*B2
) the only function will be in transform.rotate(0,0,FUN) (Unity code)
Is there a solution to this problem? Or you have to register the change in the angle of the sprite when you press the keys ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
localghost, 2015-03-13
@localghost

It's not very clear (in particular: a pair of x and y can only take 8 values?), but it seems that you need the atan2 function. Just keep in mind that it, as expected, assumes that zero degrees is in the positive direction of the x-axis.

M
Mrrl, 2015-03-13
@Mrl

45*y*(2*x^2+x-2)+90*(x^2+x+1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question