• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Checking for all solid instances

M

MrSmee

Guest
Is there an easy way to check for all instances that are solid? I'm trying to use 'collision_line() ' to make an enemy shoot only when there are no solid objects in the way. I know i could use parenting but that would complicate MANY other things in my game.

Any replies would be greatly appreciated as i can't get any further with my game until i fix this problem.
 
Last edited by a moderator:
G

Gillen82

Guest
create a parent object and give it a name of obj_solid. With any object in your game you want to make a solid object, make them a child of obj_solid.

Within the enemy step event, you could write something similar to below (adding your own player object name, and code to make the enemy fire etc):

if ( ! collision_line( x, y, obj_player.x, obj_player.y, obj_solid, false, false ) ) {

//Enemy can fire code will go here

} else {

//Enemy can't fire will go here

}
 

FrostyCat

Redemption Seeker
If you can't use parents, using a with loop is your only recourse --- and a rather inefficient one to boot.
Code:
var collide = noone;
with (all) {
  if (solid) {
    collide = collision_line(other.x, other.y, obj_player.x, obj_player.y, id, false, false);
    if (collide != noone) {
      break;
    }
  }
}
if (collide != noone) {
  //...
}
Unless the solid status changes all the time or doesn't follow a hierarchical arrangement, I strongly recommend that you look into using parents.
 
M

MrSmee

Guest
How does the use of parents complicate things for you?
In my game i have objects that sometimes hide the player and sometimes the enemy can see straight through them. If i can check all solid instances as the game is running then i can simply change whether an object is solid or not.
 
G

gn.fur

Guest
Never, ever use solid. Forget that this feature exists. It creates nothing but problems. Just use with() and parents.
 
Top