Sprite angle displayed differently

Discussion and feedback on Construct 2

Post » Tue Oct 28, 2014 3:34 pm

In my project I have different sprites. If I go into debug mode and look at the angles
of 2 specific sprites one will go from 0 to -179 then skip to 179 and continue to 0 at
which point it will go negative again and start over (it is spinning counterclockwise).
i.e. never gets higher than 180 or lower than -180.

However, the other sprite in question, when spinning counterclockwise, will start at
0 and simply decrease to negative infinity. i.e. it goes to -4056 (or whatever).

I need them to both act like the first example. I am not sure why they are working
differently. If anyone can shed some light on this I would really appreciate it.
B
4
Posts: 17
Reputation: 234

Post » Tue Oct 28, 2014 5:40 pm

Sprite's in the debugger show their angle in the range of 0-360 so I assume it's variables you have?
Sprite.Angle gives it's angle in the range 0 to 360.
The angle() expression gives a value of -180 to 180.
If you just subtract from a variable it will naturally go to negative infinity.

This will convert any angle to the range of 0 to 360:
(a%360+360)%360

This will convert any angle to the range of -180 to 180
angle(0,0,cos(a),sin(a))
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Tue Oct 28, 2014 7:46 pm

Both those formulas might be nice to have as expressions.
Image ImageImage
B
169
S
50
G
170
Posts: 8,292
Reputation: 108,728

Post » Tue Oct 28, 2014 9:06 pm

I've been able to convert the angles to a 0-360 format using % and variable.

Now I am stuck trying to get one sprite's bearing from another sprite. For example sprite A off
the nose of sprite B would return 0 degrees irrelevant of the angle of Sprite B. 270 degrees
off the direct left. 180 degrees off the tail. 90 degrees off the direct right.
B
4
Posts: 17
Reputation: 234

Post » Tue Oct 28, 2014 9:28 pm

Sprites in my debugger show their angle in 0-180. Negative when pointing up and positive for pointing down.

My problem is that one sprite will continue to increase of decrease depending on direction. while the other
will hit 180 and go negative or -180 and go positive to 0 then restart.
B
4
Posts: 17
Reputation: 234


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 12 guests