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

GameMaker [SOLVED] Fling object outwards and inwards while rotating

Kiwi

Member
Hey guys!

I'm quite new to Gamemaker, so I'm trying to learn by recreating some boss fights I like from various games.
I'm doing Marx from Kirby Super Star, and I've almost programmed all of his attacks except for this one:



I thought of achieving this by creating a spinner object called obj_spinner, and then by sticking this
into the step event:

Code:
speed -= 0.4; //reduce speed by 0.4
y+=2;
then on the object which creates the spinners, I made 2 for loops which created two cutters at each side.
(feel free to go mad at me for doing it this way, I know it's not the best)

Code:
for(var i = 0; i < 2; i++){
            var inst = instance_create_depth(x, y, obj_mbod_idle.depth+1, obj_cutter);
            inst.speed = 10; //set the speed of this cutter to 10
            inst.direction = dirl; //and set the direction to dirl, which is 180 by default.
            dirl+=30; //increase dirl by 30, to make a gap between each cutter
        }
           for(var i = 0; i < 2; i++){ //for the right side
           var inst = instance_create_depth(x, y, obj_mbod_idle.depth+1, obj_cutter);
           inst.speed = 10;
           inst.direction = dirr;
           dirr-=30;
       }

And all of that gave me this result: (couldn't put an image right here so click this https://imgur.com/eg7VVnG)

Yeah, sure, it rotates, but it doesn't move back to its starting position once out.

I then thought of an idea where I could have a 'path' for each one, where the cutter can travel outwards and inwards on.

I'll put an example here, where the pink lines indicate a path. (please excuse the crappy art)



Then I could just rotate the path from the side, like this:



which I guess MIGHT work, but I'm not entirely sure how to implement it.
Or I could play around with sin and cos to get the result I would like.

Please let me know what you think! :)
 

jo-thijs

Member
Hey guys!

I'm quite new to Gamemaker, so I'm trying to learn by recreating some boss fights I like from various games.
I'm doing Marx from Kirby Super Star, and I've almost programmed all of his attacks except for this one:



I thought of achieving this by creating a spinner object called obj_spinner, and then by sticking this
into the step event:

Code:
speed -= 0.4; //reduce speed by 0.4
y+=2;
then on the object which creates the spinners, I made 2 for loops which created two cutters at each side.
(feel free to go mad at me for doing it this way, I know it's not the best)

Code:
for(var i = 0; i < 2; i++){
            var inst = instance_create_depth(x, y, obj_mbod_idle.depth+1, obj_cutter);
            inst.speed = 10; //set the speed of this cutter to 10
            inst.direction = dirl; //and set the direction to dirl, which is 180 by default.
            dirl+=30; //increase dirl by 30, to make a gap between each cutter
        }
           for(var i = 0; i < 2; i++){ //for the right side
           var inst = instance_create_depth(x, y, obj_mbod_idle.depth+1, obj_cutter);
           inst.speed = 10;
           inst.direction = dirr;
           dirr-=30;
       }

And all of that gave me this result: (couldn't put an image right here so click this https://imgur.com/eg7VVnG)

Yeah, sure, it rotates, but it doesn't move back to its starting position once out.

I then thought of an idea where I could have a 'path' for each one, where the cutter can travel outwards and inwards on.

I'll put an example here, where the pink lines indicate a path. (please excuse the crappy art)



Then I could just rotate the path from the side, like this:



which I guess MIGHT work, but I'm not entirely sure how to implement it.
Or I could play around with sin and cos to get the result I would like.

Please let me know what you think! :)
Nice idea!

You could first try something siimpler than a path though.
The path the moons follow (without the path rotation) kind of looks like a path from jump physics.

You can simulate jump physics as follows:
Start with an initial vertical coordinate ( d ), an initial vertical velocity ( v ) and a constant vertical acceleration ( g ).
Every step, update v and d as:
v_new = v_old - g
d_new = d_old + v_new

If we write d in function of time (the amount of passed steps since the start of the jump), we get:
d ( t ) = ((t + 1) * - g / 2 + v) * t + d_initial
For the purposes we consider here, we may approximate this by:
d ( t ) = (t * - g / 2 + v) * t + d_initial
This approximation is often made by making the continuous time assumption.
If we let d_initial = 0 and we want to find the roots of d:
d ( t ) = (t * - g / 2 + v) * t = 0
we get:
t = 0 or t = 2 * v / g
So the moons return to their original position at about step t = 2 * v / g.
This gives us an idea of how fast we need to rotate the angles.

Putting all of this in code:
Spawning moons:
Code:
    for(var i = 0; i < 2; i++){
            var inst = instance_create_depth(x, y, obj_mbod_idle.depth+1, obj_cutter);
            inst.direction = dirl; //and set the direction to dirl, which is 180 by default.
            inst.initial_a *= -1;
            inst.a *= -1;
            dirl+=30; //increase dirl by 30, to make a gap between each cutter
        }
    for(var i = 0; i < 2; i++){ //for the right side
           var inst = instance_create_depth(x, y, obj_mbod_idle.depth+1, obj_cutter);
           inst.direction = dirr;
           dirr-=30;
    }
Code in moon objects:
Create event:
Code:
initial_v = 10; // initial velocity
initial_a = 15; // initial angle difference

g = 0.5; // gravity
v = initial_v; // velocity
d = 0; // distance
a = initial_a; // angle difference
Step event:
Code:
v -= g;
d += v;
a -= initial_a * g / initial_v;

x = xstart + lengthdir_x(d, direction + a);
y = ystart + lengthdir_y(d, direction + a);
Mess a bit around with the parameters and let us know how you like the effect!
 

Kiwi

Member
Nice idea!

You could first try something siimpler than a path though.
The path the moons follow (without the path rotation) kind of looks like a path from jump physics.

You can simulate jump physics as follows:
Start with an initial vertical coordinate ( d ), an initial vertical velocity ( v ) and a constant vertical acceleration ( g ).
Every step, update v and d as:
v_new = v_old - g
d_new = d_old + v_new

If we write d in function of time (the amount of passed steps since the start of the jump), we get:
d ( t ) = ((t + 1) * - g / 2 + v) * t + d_initial
For the purposes we consider here, we may approximate this by:
d ( t ) = (t * - g / 2 + v) * t + d_initial
This approximation is often made by making the continuous time assumption.
If we let d_initial = 0 and we want to find the roots of d:
d ( t ) = (t * - g / 2 + v) * t = 0
we get:
t = 0 or t = 2 * v / g
So the moons return to their original position at about step t = 2 * v / g.
This gives us an idea of how fast we need to rotate the angles.

Putting all of this in code:
Spawning moons:
Code:
    for(var i = 0; i < 2; i++){
            var inst = instance_create_depth(x, y, obj_mbod_idle.depth+1, obj_cutter);
            inst.direction = dirl; //and set the direction to dirl, which is 180 by default.
            inst.initial_a *= -1;
            inst.a *= -1;
            dirl+=30; //increase dirl by 30, to make a gap between each cutter
        }
    for(var i = 0; i < 2; i++){ //for the right side
           var inst = instance_create_depth(x, y, obj_mbod_idle.depth+1, obj_cutter);
           inst.direction = dirr;
           dirr-=30;
    }
Code in moon objects:
Create event:
Code:
initial_v = 10; // initial velocity
initial_a = 15; // initial angle difference

g = 0.5; // gravity
v = initial_v; // velocity
d = 0; // distance
a = initial_a; // angle difference
Step event:
Code:
v -= g;
d += v;
a -= initial_a * g / initial_v;

x = xstart + lengthdir_x(d, direction + a);
y = ystart + lengthdir_y(d, direction + a);
Mess a bit around with the parameters and let us know how you like the effect!
https://imgur.com/a/Qvrt0Le
Yaaay, that worked! Thank you ;)
 
Top