Rotating Object Angle Less-Than-Zero

Get help using Construct 2

Post » Fri Jul 17, 2015 2:33 pm

For my game, I had my artist send me 70+ frames of a 3D-drawn spaceship (think Donkey Kong Country or Super Mario RPG in terms of 3D graphics in a 2D environment). I wanted to capture as realistic shading/lighting as could be and I wanted to utilize her unique skills as a 3D modeler. (I say this because I know someone is going to ask why I don't just use a single image and rotate it like normal. This is why.)

I'm pinning this object with the 70+ frames to another object that will actually do all the movement and rotate as normal using the Rotate Clockwise/Counter-Clockwise actions. The angle of this object, which I call ShipBase, will determine which frame comes into play with the ShipImage object that the players will see. For instance, if the ShipBase is between angle -3 and +3, then the ShipImage will be frame 54 (which has the ship facing to the right).

As ShipBase rotates ±5 degrees, the frame of ShipImage will update to reflect the new angle range. This will not be a problem to do as I can set up two variables to calculate the Current Angle versus the Past Angle and track the overall value in the delta of the angle. However, the problem I will face is when the angle rotates "below zero". If the Current Angle is 1 and then rotates below zero, then C2 will consider the updated angle is 359 or less. When I compare the difference between Current Angle and Past Angle, this will result in a value far greater than 5 and throw off my pending system to determine when to update the frame for ShipImage. Since C2 does not actually return negative-value angles (though it can calculate them), is there any way to account for the change from positive-value angles to negative-value angles via a counter-clockwise rotation?
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
139
S
22
G
8
Posts: 774
Reputation: 14,822

Post » Fri Jul 17, 2015 2:46 pm

I guess the easiest way would be putting the frames in order..

that way you can divide 360 degrees by a number to get the right frame
using an shipbase.angle is between 3 and 357
and adding an else for the angles between -3 and 3
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 17, 2015 2:51 pm

I don't know if this will do what you want but, instead of calculating the difference and stuff, try to every time you change the shipbase angle you set the frame of shipimage to floor(shipbase.angle/5).
This might work if you take your time to organize the frames so the 0 is the frame of the ship facing right and so on.
B
17
S
7
Posts: 277
Reputation: 2,514

Post » Fri Jul 17, 2015 3:01 pm

@LittleStain - That's what I had in mind, but that would be a ton of event lines, which is what I'm trying to avoid.

@RayKi - I'm not sure I'm totally following how that will work. Could you explain the logic flow, please?

Thank you both for your input!
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
139
S
22
G
8
Posts: 774
Reputation: 14,822

Post » Fri Jul 17, 2015 3:14 pm

Rhindon wrote:@LittleStain - That's what I had in mind, but that would be a ton of event lines, which is what I'm trying to avoid.

@RayKi - I'm not sure I'm totally following how that will work. Could you explain the logic flow, please?

Thank you both for your input!


No, it wouldn't be a ton of lines..
My suggestion is almost completely the same as RayKi

you want to change the frame every 6 degrees if I understand correctly..
if it's 5 degrees change it to 5..

System every tick - set animation frame to floor(shipbase.angle/6)

so if shipbase.angle is 180 this would call frame 30
so if shipbase.angle is 90 this would call frame 15
so if shipbase.angle is 0 this would call frame 0

It would only be a matter of putting the frames in order..

i added the else condition for you want the frame between 357 and 3 degrees to be 0
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 17, 2015 4:06 pm

You can keep track of the "delta angle" using the anglediff function. It returns the smallest difference between 2 angles. i.e. 355 - 5 = 10 or 5 - 355 = 10
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Fri Jul 17, 2015 4:14 pm

You can do it all with a single line of code

set animation frame ceil(70*(1+ShipBase.Angle/360)-0.5)%70

Just add a blank image as 0
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Fri Jul 17, 2015 5:58 pm

Got it. Thanks, everyone. I'll give that a go.
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
139
S
22
G
8
Posts: 774
Reputation: 14,822


Return to How do I....?

Who is online

Users browsing this forum: mindragon73, puntodamar, zenox98 and 22 guests