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

Legacy GM Make spikes follow object

H

HenrikoNumberOne

Guest
Hi! I'm making these spikes which are supposed to follow this object as it goes up and down continuously. However, I can't seem to get it to work. Here is a picture of the current setup;



The blue thing is my object, which is supposed to go up and down with spikes on the bottom and the top. My problem lies in having the spikes follow this object as it goes up and down. It also has to work with multiple of the same objects in the same room.

Firstly, I have this code in this object's create event (which, if we'll call it by it's real name, obj_tall_spike_moving):

Code:
instance_create(x, y, obj_spikes_tall_moving_top);
... which simply creates the spike object I need. But that's it. I would preferably not have the spikes and obj_spikes_tall_moving share the same sprites and mask, that's why I want them as separate objects but still attached to each other and affected by the main object's movement. The spikes (and the core object) need to be able to switch direction if any of them hit a wall, too. Any help would be much appreciated!

- Henriko
 
Last edited by a moderator:
S

steskle

Guest
A rather simple solution would be making the blue "core" create both upper and lower spike and make them all move at unison. I just made a quick example using timelines, but I'm sure there are dozens of other more reliable methods.


create event of the blue square ("bluething" are actually the spikes):



result:

 
H

HenrikoNumberOne

Guest
A rather simple solution would be making the blue "core" create both upper and lower spike and make them all move at unison. I just made a quick example using timelines, but I'm sure there are dozens of other more reliable methods.


create event of the blue square ("bluething" are actually the spikes):



result:

That should work awesome, thanks!

Edit: Whelp, I don't own Game Maker Studio 2 so your method won't work, unfortunately :/
 
Last edited by a moderator:
H

HenrikoNumberOne

Guest
Just use instance_create() instead of instance_create_depth().
Oh awesome!

A rather simple solution would be making the blue "core" create both upper and lower spike and make them all move at unison. I just made a quick example using timelines, but I'm sure there are dozens of other more reliable methods.


create event of the blue square ("bluething" are actually the spikes):



result:

Okay, but I don't quite understand how I'm supposed to use time lines for movement as I've never used time lines before. Do you have any example code for a timeline, to make it move as the object you made above?
 

samspade

Member
Oh awesome!



Okay, but I don't quite understand how I'm supposed to use time lines for movement as I've never used time lines before. Do you have any example code for a timeline, to make it move as the object you made above?
I was curious about timelines too as I've never used them before, so I went and watched the following video. They're pretty cool. Probably worth learning as there are somethings they would work nicely for, and I think it would be pretty easy to create a time line that would do what you want.



However, I would have done this:

Code:
///create event of object

var temp_offset = 20;                                      
repeat (2) {                                                      
    with (instance_create(x, y, obj_spike) ) {
        parent = other.id;
        offset = temp_offset;    
    }
   temp_offset *= -1;
}


///create event of spike

parent = noone;
offset = 0;

///step event of spike

x = parent.x;
y = parent.y + offset;
This will create two spikes and lock the position of those spikes to the object (regardless of whether or not that object moves). You don't really need to use a repeat condition here. You could just do two create events, but I like it because with very little work you could set it up to spawn a spike on all four sides, or in a ring around the object, and so on.
 
H

HenrikoNumberOne

Guest
I was curious about timelines too as I've never used them before, so I went and watched the following video. They're pretty cool. Probably worth learning as there are somethings they would work nicely for, and I think it would be pretty easy to create a time line that would do what you want.



However, I would have done this:

Code:
///create event of object

var temp_offset = 20;                                     
repeat (2) {                                                     
    with (instance_create(x, y, obj_spike) ) {
        parent = other.id;
        offset = temp_offset;   
    }
   temp_offset *= -1;
}


///create event of spike

parent = noone;
offset = 0;

///step event of spike

x = parent.x;
y = parent.y + offset;
This will create two spikes and lock the position of those spikes to the object (regardless of whether or not that object moves). You don't really need to use a repeat condition here. You could just do two create events, but I like it because with very little work you could set it up to spawn a spike on all four sides, or in a ring around the object, and so on.
You're a life saver! Thanks :)
 
Top