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

Object not Working as Sensor

AbdatyK

Member
Hello, I'm relatively new to GameMaker so I'm trying to follow along a youtube tutorial by HeartBeast (found here). I'm aware that he's using an outdated version of GameMaker but I've been able to get by using the manual to fill in the gaps. What I'm stuck on is the damage object that is initialized when the player begins his attack animation. From what I understand, what makes the collision event be called one time instead of each step is marking the damage object as a sensor. However, checking the sensor box didn't work so my enemies are being killed in one hit since the damage is being applied so many times. My room and objects all use physics, and I even tried making a fixture and assigning it to the damage object in its create event, but it still doesn't act as a sensor object.

This is the code that is in the create event of my damage object.
GML:
// Sets the damage referenced in the collision event
damage = 1;

creator = noone;

// Creates a fixture and binds it to the damage object
var fixture = physics_fixture_create();
physics_fixture_set_box_shape(fixture, sprite_width/2, sprite_height/2);
physics_fixture_set_density(fixture, 0.5);
physics_fixture_set_restitution(fixture, 0.2);
physics_fixture_set_friction(fixture, 0.5);
physics_fixture_set_sensor(fixture, 1);
physics_fixture_bind(fixture, obj_damage);
This code is in the collision event of the damage object, when colliding with a lifeform object which is the parent of my enemies and player.
GML:
// Damages the other object if the object is not the one attacking
if (other.id != creator) {
    other.hp -= damage
}

// Sets an alarm to destroy the instance
alarm[0] = 1;
I'm using version 2.3.4.580
Thank you all in advance
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Hmmmm... The manual does state that sensor events should only fire once. If that is NOT the case (and it's easily tested, just stick a show_debug_message into the collision event and see how many times it shows up in the output window), then PLEASE file a bug report with YoYo Games and include an exported YYZ of the file. Either this is a bug that needs to be fixed, or it is a change that needs to be documented...

As to fixing the issue, that's easy, you'll be glad to hear! :)

Just change the collision event like this:
GML:
if alarm[0] < 0
{
// Damages the other object if the object is not the one attacking
if (other.id != creator) {
    other.hp -= damage
    }
// Sets an alarm to destroy the instance
alarm[0] = 1;
}
By checking the alarm like this you are assured that the event will only trigger once before the instance is destroyed.
 

AbdatyK

Member
Hmmmm... The manual does state that sensor events should only fire once. If that is NOT the case (and it's easily tested, just stick a show_debug_message into the collision event and see how many times it shows up in the output window), then PLEASE file a bug report with YoYo Games and include an exported YYZ of the file. Either this is a bug that needs to be fixed, or it is a change that needs to be documented...

As to fixing the issue, that's easy, you'll be glad to hear! :)

Just change the collision event like this:
GML:
if alarm[0] < 0
{
// Damages the other object if the object is not the one attacking
if (other.id != creator) {
    other.hp -= damage
    }
// Sets an alarm to destroy the instance
alarm[0] = 1;
}
By checking the alarm like this you are assured that the event will only trigger once before the instance is destroyed.
After changing it to what you suggested and using the show_debug_message() function, it stopped damaging the enemy object altogether. Based on the debug messages the code under the second if statement wasn't being run at all, do you still think this is just a bug and I should report it?
Thank you

EDIT: I suspect that the first thing it collides with is the player, so after declaring that statement false it sets the alarm and therefore doesn't check any collisions after that. I haven't found any workarounds yet

I still need help, if that wasn't clear
 
Last edited:
Top