• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

Collide with object a certain distance.

Good day and Excuse me for my English. I would like you to help me with a problem I have when colliding with a certain object.
I have a parent object that is par_wall that has as children the object obj_wall.

data:
-obj_player: dimensions = 32 x 64 px, origin = 16 x 63, botton center, collision mask automatic.
-obj_wall: dimensions = 32 x 16 px, origin = 16 x 15, botton center.
-in the create event of obj_wall I have the variable type = 2,

I'm doing a Beat 'em up game, I want the obj_player to collide with obj_wall(pole) from the bottom up at a certain distance, like colliding with a pole or stick.
I can collide from left to right, from right to left, from top to bottom.

here is the code to collide from bottom to top, but the obj_player collides with the top and stops, I want the obj_player to go through the obj_wall(pole) and stop at a certain distance.
I do not want to change the collision mask, because I will use it to collide with blows.

Create:
vsp = 0;
grounded = 0;
flip = 1;

Step:

//Move left and right
if (Key_Left)
{
hsp = -5;
flip = -1;
}

if (Key_Right)
{
hsp = 5;
flip = 1;
}

if (Key_Up)
{
vsp = -5;
//flip = 1;
}

if (Key_Down)
{
vsp = 4;
//flip = 1;
}

//Vertical Collision

var vcollide;
vcollide = instance_place(x,y+vsp,par_wall);

if (vcollide != noone)
{
if (((vcollide).type == 2) && sign(vsp) == -1)
{
if (!place_meeting(x,y,par_wall))
{
while (!place_meeting(x,y+sign(vsp),par_wall))
{
y+=sign(vsp)
}
vsp=0;
grounded = 1;
}
}
}

else grounded = 0;
y+=vsp;

Captura.PNG
 

jobjorgos

Member
If I dont misunderstand what you want, it can be simply solved I think by making beside the real wall object, a fake one (lets say obj_fake_wall) which is invisible and make it also a parent of obj_wall. Edit the mask of obj_fake_wall to your desire.
Because you said obj_wall already has par_wall as parent, you have to set the parent of par_wall to obj_fake_wall.
Or might without the uses of childs/parents just make a code for obj_wall create event with instance_create(obj_fake_wall,x,y); with the same origin positions but different masks for both objects. If you dont always want obj_fake_wall to be active u can make a variable maybe to trigger it when you need to.
 
Top