Rotating Object Angle Less-Than-Zero

0 favourites
  • 8 posts
From the Asset Store
“Zero Numbers” is a logic game. Game with Source-Code (Construct 3 / .c3p) + HTML5 Exported
  • 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 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 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.

  • 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!

  • 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

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • Got it. Thanks, everyone. I'll give that a go.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)