orbit mouse | gml
a gml implementation of this
sprCharacter, middle-centre origin:
objCharacter Create
player_step_speed = 3; orbital_step = 0;
objCharacter Step
var left = keyboard_check(ord("A")); var right = keyboard_check(ord("D")); var up = keyboard_check(ord("W")); var down = keyboard_check(ord("S")); direction = point_direction(x,y,mouse_x,mouse_y); image_angle = direction; distance = point_distance(x, y, mouse_x, mouse_y); if(orbital_step >= 360) orbital_step = 0; if (left) { orbital_step = orbital_step - player_step_speed; } if (right) { orbital_step = orbital_step + player_step_speed; } if (up) { speed = player_step_speed; } if (down) { speed = -player_step_speed; } if not(up) and not(down) speed = 0; var vector_x = lengthdir_x(distance, orbital_step); var vector_y = lengthdir_y(distance, orbital_step); if (left or right) { x = mouse_x + vector_x; y = mouse_y + vector_y; } else { if (direction >= 180) { orbital_step = direction mod 180; } else { orbital_step = direction + 180; } }