E
ERIKLRL
Guest
I'm trying to make a script for the collision event because I use too many collision events and is not very efficient. I tried place_meeting in the step event and it doesn't execute when collided. Can someone help? Thanks.
Im confused, are you asking for help writing your own collision checks? Because they're tons of resources you can find online for it. Shaun Spaudling has a nice short video explaining the concept, and even includes a code demonstration in the description. That being said are you using the gamemaker physics system? Cause if so what you can do is check for collisions with parent objects rather than each object you need to be able to collide with.I'm trying to make a script for the collision event because I use too many collision events and is not very efficient. I tried place_meeting in the step event and it doesn't execute when collided. Can someone help? Thanks.
My problem is that place_meeting doesn't work. It doesn't execute the code when I collide with the object. I'm not using the physics system.Im confused, are you asking for help writing your own collision checks? Because they're tons of resources you can find online for it. Shaun Spaudling has a nice short video explaining the concept, and even includes a code demonstration in the description. That being said are you using the gamemaker physics system? Cause if so what you can do is check for collisions with parent objects rather than each object you need to be able to collide with.
Are you by chance doing something like place_meeting(x,y,col_obj). This will only return true if the sprite mask overlap. What you need to do is check some pixels ahead. For example place_meeting(x,y+1,col_obj) is basically a ground check of sorts. Take a look at the shaun spaulding video I linked and you'll understand what I mean a bit more.My problem is that place_meeting doesn't work. It doesn't execute the code when I collide with the object. I'm not using the physics system.
If they're all doing the same thing, you should be making a "parent enemy" object and setting all existing enemies as its children. Then you can just check for collisions with that parent instead of the children individually. It applies regardless of whether you use collision events or step collision checks.I've tried place_meeting, instance_place, collision_point, none worked. The objects have masks. The code is just if(instance_place(x,y,object)){things to execute} in the step event. The things to execute works fine in the collision event, but when I move it to the step event with instance_place or place_meeting, it just doesn't work. I have a lot of collision events with enemies in the player object, and they all do the same thing, so all I'm trying to do is to have a collision script to simplify things. But I don't know why it doesn't work.
var inst_enemy = instance_place(x, y, obj_enemy);
if (inst_enemy != noone) {
with (inst_enemy) instance_destroy();
}
I didn't use a parent object because is only the collision code that's the same, each enemy has different codes. For some reason, instance_place just don't work in the player object. I can't figure out why.If they're all doing the same thing, you should be making a "parent enemy" object and setting all existing enemies as its children. Then you can just check for collisions with that parent instead of the children individually. It applies regardless of whether you use collision events or step collision checks.
Also, if you are using other in an actual collision event, that code CANNOT be reused verbatim in a step collision check. Instead, you need to use collision checking functions that return instance IDs (instance_place(), instance_position() and collision_*() functions not ending in _list) and put that instance ID where other used to be.
Code:var inst_enemy = instance_place(x, y, obj_enemy); if (inst_enemy != noone) { with (inst_enemy) instance_destroy(); }
Nobody said you have to inherit any common properties or behaviours from a parent object. It's common for objects in GM to inherit off a completely blank parent object that never gets instantiated, just to get them to count as an aggregate group for use with collision functions or with blocks.I didn't use a parent object because is only the collision code that's the same, each enemy has different codes. For some reason, instance_place just don't work in the player object. I can't figure out why.