How to make solid walls?

N

Noba

Guest
Anyone know a quick and easy way to do this?

Every single video I've found has been half an hour long and right now I haven't got the time since I need to get this implemented quickly. It needs to also work for the enemies, their ai doesn't need to work in a way where they actively try to avoid walls since they way they're designed means that doesn't matter attack wise (in a way).
 

NightFrost

Member
Simple collision detection is about the quickest you can do, and if you're not familiar with how to do it there's really no way around either reading an article or watching a video on how to build it. Physics engine enabled room might have faster solutions but I have never used it, and AFAIK it changes how object movement is done.
 
N

NeonBits

Guest
Make an obj_wall, click "solid" in its box, select a collision check event on the next section, chose an object that must not pass the wall, add a code page in the final section and write: //collision check or what you want. The selected object will instantly be blocked. Add as many collision event that you wish. Make sure your obj_wall has a sprite : P
 
N

Noba

Guest
Make an obj_wall, click "solid" in its box, select a collision check event on the next section, chose an object that must not pass the wall, add a code page in the final section and write: //collision check or what you want. The selected object will instantly be blocked. Add as many collision event that you wish. Make sure your obj_wall has a sprite : P
Really? That works?
 
N

Noba

Guest
Make an obj_wall, click "solid" in its box, select a collision check event on the next section, chose an object that must not pass the wall, add a code page in the final section and write: //collision check or what you want. The selected object will instantly be blocked. Add as many collision event that you wish. Make sure your obj_wall has a sprite : P
Err, I tried it, but enemies get stuck on the walls (and so does the player!)
 

LanNet

Member
I
Make an obj_wall, click "solid" in its box, select a collision check event on the next section, chose an object that must not pass the wall, add a code page in the final section and write: //collision check or what you want. The selected object will instantly be blocked. Add as many collision event that you wish. Make sure your obj_wall has a sprite : P
In this approachment, you must aware and take care the sprite collision mask. If more often the player/enemy change sprites, the more chances it will be stuck on the wall. In movement, you may need to add a code in the beginning: If place_free(x,y) ... before perform any move direction to prevent it 'passing' the wall and gettin' stuck there.
 
N

NeonBits

Guest
I'm sorry, I didn't thought about animation, only how to make a wall solid. I remember scratching my head alot to fix the animation; one pixel can be a pain and specialy when the animation is not well balanced or with precise collision check. To use a different mask with the object instead of the animated sprites will save you alot of troubles. You will only need to set things to make the illusion perfect in the environment.
 
N

Noba

Guest
I

In this approachment, you must aware and take care the sprite collision mask. If more often the player/enemy change sprites, the more chances it will be stuck on the wall. In movement, you may need to add a code in the beginning: If place_free(x,y) ... before perform any move direction to prevent it 'passing' the wall and gettin' stuck there.
I'm sorry, I didn't thought about animation, only how to make a wall solid. I remember scratching my head alot to fix the animation; one pixel can be a pain and specialy when the animation is not well balanced or with precise collision check. To use a different mask with the object instead of the animated sprites will save you alot of troubles. You will only need to set things to make the illusion perfect in the environment.
I'm still a bit confused about how to do it without them getting stuck-
None of the objects change sprite aside from the player, but the player rotates which is how they get stuck.
Is there anything else I could do? Or should I just spend a good half an hour looking up a tutorial on how to set it up properly?
 
W

Whirlpoolio

Guest
What I do is make the block solid and make sure the collision masks are finely tuned. Then I make it so the enemy and player collides with the wall.
Also because you are having problems with that method, I wipped up some code for you (should work) that doesn't require any collision events. Only a step and create event. It makes it so the enemy goes in one direction till it hits a wall and then it turns the other direction. This method is used (I think) in Super Crate Box. Hopefully it will work for you.
Code:
/// Collision AI (in step event)
hspd = dir*spd;
vspd += grav;

// Horizontal Collisions
if (place_meeting(x + hspd,y,oSolid)) {
     while (!place_meeting(x+sign(hspd),y,WALL_OBJECT_NAME)) {
        x+=sign(hspd);
     }
     hspd = 0;
     // Flips direction
     dir *= -1
}
x+=hspd
// Vertical Collisions
if (place_meeting(x,y+ vspd,oSolid)) {
     while (!place_meeting(x,y+sign(vspd),WALL_OBJECT_NAME)) {
        y+=sign(vspd);
     }
     vspd = 0;
     // Flips direction
     dir *= 1
}
y+=vspd
Code:
/// Scaling (step event)
if (dir == -1) image_xscale=-1;
else image_xscale=1;
Code:
/// Define some variables ( Create event)
randomize();
// -1 = left, 1 = right
dir = choose(-1,1)
spd = 6;
hspd = 0;
vspd = 0;
grav = 1.2;
hp = 50;
damage=2;
image_speed = .4;
 
N

Noba

Guest
What I do is make the block solid and make sure the collision masks are finely tuned. Then I make it so the enemy and player collides with the wall.
Also because you are having problems with that method, I wipped up some code for you (should work) that doesn't require any collision events. Only a step and create event. It makes it so the enemy goes in one direction till it hits a wall and then it turns the other direction. This method is used (I think) in Super Crate Box. Hopefully it will work for you.
Code:
/// Collision AI (in step event)
hspd = dir*spd;
vspd += grav;

// Horizontal Collisions
if (place_meeting(x + hspd,y,oSolid)) {
     while (!place_meeting(x+sign(hspd),y,WALL_OBJECT_NAME)) {
        x+=sign(hspd);
     }
     hspd = 0;
     // Flips direction
     dir *= -1
}
x+=hspd
// Vertical Collisions
if (place_meeting(x,y+ vspd,oSolid)) {
     while (!place_meeting(x,y+sign(vspd),WALL_OBJECT_NAME)) {
        y+=sign(vspd);
     }
     vspd = 0;
     // Flips direction
     dir *= 1
}
y+=vspd
Code:
/// Scaling (step event)
if (dir == -1) image_xscale=-1;
else image_xscale=1;
Code:
/// Define some variables ( Create event)
randomize();
// -1 = left, 1 = right
dir = choose(-1,1)
spd = 6;
hspd = 0;
vspd = 0;
grav = 1.2;
hp = 50;
damage=2;
image_speed = .4;
Well I managed to fix the player by using some other code that checked for movement AND collisions with the wall.
And err, I would use that code but all of the enemies are pretty basic, they just go towards the player.

I also thought that using the code for the player would work, but it doesn't.
Here's what I'm using;
Code:
if(instance_exists(oPlayer) && !place_meeting(x + 50,y + 50, oCollide))
{
    move_towards_point(oPlayer.x,oPlayer.y,spd)

}
Could it be because instead of the player, the normal enemies have hit boxes that take up their entire sprite?
 
F

FireBlox

Guest
anyone know how to do walls without using GML? or if you can?
 
Top