GMS 2 Multiple Object collision possible?

Hey yo!

I've searched through the forum but couldnt quite find a fitting solution for my problem.
I hope one of yall can help me:

I am making a simple 2D Platformer on GMS 2.
I wrote a code, so if the player gets near "Obj_Block_1" the Player collides with the Object. In other terms it becomes solid.
I now want to use a different sprite/object e.g. a Block that looks different than "Obj_Block_1"... But I want it to have the same properties.
Whatever I do The player walks on "Obj_Block_1" but he falls right through every other object.

Maybe there is a way to sum up the objects into one var? I dunno :/
It would be awesome if somebody can help me understand this problem or even fix it :)

Btw here is my collision code:

//Collision
if (place_meeting(x + hspeed, y, Obj_Block_1))
{
while(!place_meeting(x + sign(hspeed), y, Obj_Block_1))
{
x += sign(hspeed);
}


hspeed = 0;
}

if (place_meeting(x, y + vspeed, Obj_Block_1))
{
while(!place_meeting(x, y + sign(vspeed), Obj_Block_1))
{
y += sign(vspeed);
}


vspeed = 0;
}

if (place_meeting(x + hspeed, y + vspeed, Obj_Block_1))
{
hspeed = 0;
vspeed = 0;
}
 

NightFrost

Member
Yes. Create a parent object that all terrain objects will use, and run player's collision checks against that.
 

NightFrost

Member
Hey thanks for the fast reply!
Can you explain me how do I create a parent object?
Create a new object and name it in a manner that explains its use, ie Obj_Block_Parent. Parenting is done via the Parent button in the objects. Either do it through the parent by clicking the plus symbol and choose its children, or open the child objects and select a parent through the same interface's Parent section. Finally, in the code you showed above, replace all Obj_Block_1 with Obj_Block_Parent. Now the collision will check against all instances of objects that have been made children of Obj_Block_Parent.
 
Create a new object and name it in a manner that explains its use, ie Obj_Block_Parent. Parenting is done via the Parent button in the objects. Either do it through the parent by clicking the plus symbol and choose its children, or open the child objects and select a parent through the same interface's Parent section. Finally, in the code you showed above, replace all Obj_Block_1 with Obj_Block_Parent. Now the collision will check against all instances of objects that have been made children of Obj_Block_Parent.
Thank you very much!
 
Top