D
Dibidoolandas
Guest
I've come upon this issue a couple of times and always found a workaround, but I feel like there must be an elegant solution. I am working on a platformer, and in this level I have these little rolling hazards that move around and sometimes smash through destructible environmental elements. Here is the code I have on the roller to tell it to smash through destructible terrain:
var hdestroy;
hdestroy = instance_place(x+hsp,y,par_destructible);
if (hdestroy != noone)
{
if (abs(hsp) >= 5) //if the roller is moving fast enough
{
with(hdestroy) hp -= 1; //destroy the terrain
}
}
It's pretty simple, but it works if there's a block in the way. However, if there are two blocks in the way, and it touches both at the same time, it will destroy one and bounce back off the other. Now, elsewhere in my movement code I tell it to bounce off of solid objects, so that's where this behavior comes in. I could post that code, but I don't know that it's relevant and is more complex... Let me know if this doesn't show the whole picture though. I whipped up a quick diagram.
I think I understand what's happen. As part of the step event, the roller detects it's going to hit the block so it destroys it. However at the same time it detects it's still going to hit that other block, and so it runs its typical bounce-off solid objects code. I need to change the destroy code to basically say if you come into contact with ANY instances of destructible objects in each step, subtract 1 hp from them (destroy them). I'm not sure how to detect that though. Any help would be greatly appreciated. Thanks!
var hdestroy;
hdestroy = instance_place(x+hsp,y,par_destructible);
if (hdestroy != noone)
{
if (abs(hsp) >= 5) //if the roller is moving fast enough
{
with(hdestroy) hp -= 1; //destroy the terrain
}
}
It's pretty simple, but it works if there's a block in the way. However, if there are two blocks in the way, and it touches both at the same time, it will destroy one and bounce back off the other. Now, elsewhere in my movement code I tell it to bounce off of solid objects, so that's where this behavior comes in. I could post that code, but I don't know that it's relevant and is more complex... Let me know if this doesn't show the whole picture though. I whipped up a quick diagram.
I think I understand what's happen. As part of the step event, the roller detects it's going to hit the block so it destroys it. However at the same time it detects it's still going to hit that other block, and so it runs its typical bounce-off solid objects code. I need to change the destroy code to basically say if you come into contact with ANY instances of destructible objects in each step, subtract 1 hp from them (destroy them). I'm not sure how to detect that though. Any help would be greatly appreciated. Thanks!