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

How do you rotate a Game Object around a specified point?

king_frnk

Member
I was working on a small game to get my experience up and I wanted to remake a game called "Pick the Lock". Fast forward>> I wanted to know how to rotate the player object around a specific point in the room; So it would look like it's going in circles? Any help?

This is the code I have so far:

image_angle = point_direction(x, y, obj.x, obj.y);
 
To give a little more detail. The lengthdir_* functions take a length and a direction and "cast" out to a point using that length and direction. So if you want something to rotate around a point it would look like this:
Code:
var xx = point_x+lengthdir_x(length,direction);
var yy = point_y+lengthdir_y(length,direction);
xx and yy would now hold the point that is rotating. To make it actually rotate over time, you would simply increase the direction variable over time.
 

woods

Member
here is a couple examples that ive used in early GMS1 days..
just dinkin around with making things move how i want them to.

get a ship to rotate around a planet
Code:
//ship create event

distance = 100;
dir = 0;


//ship step event

if (keyboard_check(ord("A"))) //rotate
    dir += 10;
if (keyboard_check(ord("D"))) //rotate
    dir -= 10;

if (keyboard_check(ord("w"))) //distance
    distance += 10;
if (keyboard_check(ord("S"))) //distance
    distance -= 10;

x = inst_planet.x + distance*dcos(dir);
y = inst_planet.y - distance*dsin(dir);

rotate gun around the player targeting mouse
Code:
//gun step event

image_angle = point_direction(obj_player.x, obj_player.y, mouse_x, mouse_y);

x = obj_player.x + lengthdir_x(64, image_angle);
y = obj_player.y + lengthdir_y(64, image_angle);
 
Top