GML What's the code equivalent for the collision event?

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.
 
P

Pyxus

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.
 
E

ERIKLRL

Guest
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.
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.
 
Have you read the Collisions section of the manual?

Is place_meeting() the only function you have tried?

Post your code you have so far so we can help.
 
P

Pyxus

Guest
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.
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.
 

TsukaYuriko

☄️
Forum Staff
Moderator
The equivalent is instance_place, the return value of which can be accessed via other in the Collision event.

If your code is not registering collisions (and that's not due to your usage of place_meeting instead of instance_place, as they are functionally equivalent apart from their return value), the source of it lies outside of the collision code (for example with collision masks) or your specific implementation of these functions, the code of which is not included in your post, making it impossible for us to provide more specific help.

Please post all relevant code if you require further assistance.
 
E

ERIKLRL

Guest
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.
 

FrostyCat

Redemption Seeker
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.
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();
}
 
E

ERIKLRL

Guest
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();
}
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.
 

flerpyderp

Member
Is there a reason for you withholding the relevant code that has been requested?

Until you do, all we can give are potential solutions to a currently undefined problem.
 
Last edited:

FrostyCat

Redemption Seeker
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.
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.
 
Top