S
Sir_Rysik
Guest
Hey everyone!
I'm having a problem with the collision_rectangle function in game maker where it's not registering any collisions. The picture provided is an example of what I am using it for. The Orange square will represent the object calling the collision code. The white/yellow/red box is the collision check area. And the gray squares are the objects that it's checking against.
Basically I want the orange object to check a 2x3 grid area in front of and on top of it (In this case the collision area is slightly smaller for the sake of performance (Upping the size has no effect)). If the specified object is within the area then the orange block will destroy itself.
As you can see the collision area should be triggered (represented by the bright red areas). But for some reason the object doesn't destroy itself. As far as I can tell the object will only destroy itself if it is on top of the object it's checking for.
Here is my code:
Create
Code:
/// @description Initialize Variables
Direction = "";
randomize();
Number = irandom_range(3,6);
X = 0;
Y = 0;
alarm[0] = 120;
Code:
/// @description Create Walls
if (Number == 0)
{
exit;
}
//Check Collisions
switch(Direction)
{
case "Right":
if (collision_rectangle(x + 8, y - 8, x + 24, y + 24, Obj_Solid_Parent, false, true) != noone)
{
instance_destroy();
}
X = 1;
break;
case "Up":
if (collision_rectangle(x - 8, y - 8, x + 24, y + 8, Obj_Solid_Parent, false, true) != noone)
{
instance_destroy();
}
Y = -1;
break;
case "Left":
if (collision_rectangle(x - 8, y - 8, x + 8, y + 24, Obj_Solid_Parent, false, true) != noone)
{
instance_destroy();
}
X = -1;
break;
case "Down":
if (collision_rectangle(x - 8, y + 8, x + 24, y + 24, Obj_Solid_Parent, false, true) != noone)
{
instance_destroy();
}
Y = 1;
break;
}
//Create Wall
instance_create_depth(x, y, -100, Obj_Dungeon_Walls);
Number--;
//Move
x += X * 16;
y += Y * 16;
alarm[0] = 120;
Any help would be greatly appreciated!