• 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!

how to make a non-solid object behave like a solid object for enemy?

pixeltroid

Member
I'm thinking of an object with a 32x32 sprite and mask that I can lay around the room. I should be able to walk through it like it isn't there, but certain enemies should not be able to pass through it, and should react to it the way it would when it touches a solid object.

The reason is I am trying to create an easy to revise "boundary" for certain special enemies and bosses....and preventing them from entering certain areas.

Any ideas as to how I should go about this?
 

NightFrost

Member
Create a common parent object for all your walls and other solid things. Normal entities use that for collision detection. Create another parent object which has the first parent and nonsolid things as its children. Entities that should not pass through nonsolids use that for collision detection.
 

Coded Games

Member
I'm fairly certain all "solid" does is move the non solid object back to the previous x/y in the collision event.

If you have o_player and o_wall and o_player has a collision event with o_wall:

All that solid does is this:
GML:
x = xprevious;
y = yprevious;
So uncheck solid from o_wall or whatever and add that code to any objects that you want to mimic solid for.

Edit: Just checked, that is almost the exact code for solid in the documentation:
Code:
if other.visible = true
    {
    x = xprevious;
    y = yprevious;
    }
 

Nidoking

Member
Note that functions like place_free depend on the solid property, so if you've been using that, you'd need to replace it with something else. One option is to give every solid object in your game a common parent (obj_solid, say) with no functionality, then check for !place_meeting obj_solid wherever you would be checking for place_free.
 

Coded Games

Member
In general I've always heard it's kind of best practice to avoid using the solid flag as the behavior to just go back to the last x/y coordinate on collision can cause some problems. For example it may prevent you from having pixel perfect collisions. I don't use it in any of my games. And like @Nidoking said you would then not be able to use place_free. Instead you would then want to use place_meeting, instance_place, and instance_position.
 
G

GmlProgrammer

Guest
In order to tackle these kind of problems I create a custom place_free script like this:

if(object_index == *the object i want a custom rule for*){
with(other_object) solid = true;
}

var ret_value = place_free(argument0,argument1);

with(other_object) solid = false;

return ret_value;

Just a quick hack
 

Yal

šŸ§ *penguin noises*
GMC Elder
To avoid duplicating code, you could use event_perform to run the original terrain collision event.

Enemy's collision event with that invisible object:
GML:
event_perform(ev_collision,parent_terrain);
 

pixeltroid

Member
ok. I implemented the method suggested by Coded Games. It's easy to implement and works great.

Yal I was having some trouble with parent-children objects. I will try out event_collision for those objects.

I will save the methods suggested by the others in my code bank to test and study later.

Thanks for help everyone!
 
Top