• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Circle Rotation With Touch

O

omrtha

Guest
Hi, i am working on this game where i have a circle and i rotate the circle with finger touch. The problem i am having is that every time i begin to touch the screen, my circle jumps to that angle. I want that wherever i touch, the circle should rotate keeping its angle relative to the touch angle. Here is my code:

if mouse_check_button(mb_left){
image_angle = point_direction(x,y,mouse_x,mouse_y);
}

I am not sure if i could explain it but i am really frustrated and i couldn't find a solution in the last 3 days.
 

Nux

GameMaker Staff
GameMaker Dev.
You need to store the previous angle and rotate by the difference, e.g:
Code:
CREATE:
angle_previous = 0;

STEP:
var angle_target = point_direction(x,y,mouse_x,mouse_y);
if(mouse_check_button_pressed(mb_left)){
    angle_previous = angle_target; // set starting angle
} else if(mouse_check_button(mb_left)){
    image_angle -= angle_difference(angle_previous,angle_target);
    angle_previous = angle_target; // update previous angle for next step
}
 
O

omrtha

Guest
You need to store the previous angle and rotate by the difference, e.g:
Code:
CREATE:
angle_previous = 0;

STEP:
var angle_target = point_direction(x,y,mouse_x,mouse_y);
if(mouse_check_button_pressed(mb_left)){
    angle_previous = angle_target; // set starting angle
} else if(mouse_check_button(mb_left)){
    image_angle -= angle_difference(angle_previous,angle_target);
    angle_previous = angle_target; // update previous angle for next step
}
Wow, that worked you are my hero mate thanks!!!
 
Top