• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

Stopping rotation at a quarter circle? [Solved]

So, I'm making a game where, at some times, all game objects rotate around the center of the screen. I've had it working just fine until now when I want to change a thing.
The code I'm running at the moment is:

Code:
if (obj_timer.state == main_states.onRotationCW)
{
    radius = point_distance(x, y, obj_origo.x, obj_origo.y);
    angle = point_direction(x, y, obj_origo.x, obj_origo.y);
   
    angle -= rotspeed;
    image_angle -= rotspeed;
    angle = angle mod 360;
    image_angle = image_angle mod 360;
   
    if (angle < 0)
    {
        angle += 360;
    }
   
    if (image_angle < 0)
    {
        image_angle += 360;
    }
   
    x = centerX - lengthdir_x(radius, angle);
    y = centerY - lengthdir_y(radius, angle);
       
   
    if (image_angle == 90 || image_angle == 180 || image_angle == 270 || image_angle == 0)
    {
        global.turn += 1;
        turned = 1;
    }
}
This script stops running when "global.turn" equals the number of objects turning and then the game is set in another state. It's done somewhere else. I'm a messy coder. And I'm sure some of the things in there are unnecessary.

Now the thing is, with this code the objects, and their sprites, rotate around obj_origo, super good, but with my latest change I'd like it if the sprites do NOT rotate. I can get this effect by just removing everything that starts with "image_angle" but then I can't seem to find a case where I can stop the rotation at a quarter circle as is possible when checking the image_angle.

EDIT:

Basically; what do i put in the last if statement to know if there has been a quarter circle revolution if I can't use image_angle?

Any ideas or solutions?
 
Last edited:

Relic

Member
When you initially start the rotation, by setting main_states for the first time, also set a (possibly global) variable angle_change=0. Each step, add rotspeed to angle_change and your if statement can then read if angle_change>45
 
When you initially start the rotation, by setting main_states for the first time, also set a (possibly global) variable angle_change=0. Each step, add rotspeed to angle_change and your if statement can then read if angle_change>45
This would work. Just make sure to change it to angle_change > 90, 45 is an 1/8th of a circle ;)
 
Top