• 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 [SOLVED]How to move in two different objects without using parents?

B

Ben26

Guest
i have a rolling ball obstacle and i want it to move over walls and spikes
so i cant make the wall the parent of the spikes
because then the player will walk on spikes and i dont want that

code of the ball
Code:
hsp = dir * movespeed;
vsp += grav;

//HORIZONTAL COLLISION
if (place_meeting(x+hsp,y,obj_wall)) 
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
dir *= -1;
}
x += hsp;

//VERTICAL COLLISION
if (place_meeting(x,y+vsp,obj_wall)) 
{
    while(!place_meeting(x,y+sign(vsp),obj_wall)) 
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;
i tried using "or" place_meeting obj_spikes in the collision code but it freeze the game
 

FrostyCat

Redemption Seeker
Why don't you make a new object (say obj_impassible) and make the wall and spike children of it? Then the player can check against obj_impassible and the rolling ball can check against walls only.
 

Yal

🐧 *penguin noises*
GMC Elder
Read up the "parents" page in the manual.







Done? Okay, here we go.
Have a hierarchy like this:

obj_impassible
  • obj_wall
  • obj_spike
Motion planning code checks for obj_impassible
Death code checks for obj_spike
Platforming code checks for obj_wall
 
B

Ben26

Guest
so the idea is that the object impassible works as a wall
and it's the parent of the wall and spike
so the ball can walk in both
but have the player only check the collision of the wall?
 
B

Ben26

Guest
but if the wall is the child of impassible then wouldn't the player walk on the spikes too?

edit1: ok so i made a drawing to understand better i think i'm getting it now

edit2: it works as intended thanks both for the help!
 
Last edited by a moderator:
Top