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

GML Rotating one object around another?

M

Monochromatic_Hermit

Guest
So, I've been at this for a few hours and i can't seem to get it working. In the game i'm making, i want the sword to rotate around to the front of the player when they attack and then return to behind the player after the attack is done.
 

Attachments

G

Gabriel Cortabraz

Guest
I'm not really sure exactly what you want but you can do that in multiple ways, i'd say the easiest would be using lengthdir functions.

In the create event you should just create two variables for the distance between the sword and your player and another one to keep track of your sword angle

The Step Event of the Sword:
Code:
if (rotate_attack) {
    // this will start to rotate the sword
    angle += 5;
} else {
    // this is just so the sword rotates smoothly towards its default position
    var rotation_speed = 5;
    angle += sin(degtorad(180 - angle)) * rotation_speed;
   
}

// this will make the sword have a position relative to the player and around 
x = obj_player.x + lengthdir_x(distance, angle);
y = obj_player.y + lengthdir_y(distance, angle);
 
Top