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

The other term and collision

Erayd

Member
I'm having some strange feedback in my game at the moment. When the player collides with an enemy an event triggers in the player that is the collision event to an enemyBase all enemies are children of. Inside of the code the player health is lowered by the enemy strength. Very simple.

The issue pops up when I add upgrades which raise the player strength. When I change the player strength to 2 or 3, suddenly the player is taking 2 or 3 damage per hit. It does of course also give 2 or 3 damage when the player attacks. So maybe my use of "other" is wrong? I can't find any useful documentation on the use of this event or what other specifically refers to in this event.

My collision to an enemy base event inside of the player:
Code:
if(invincible == 0) {
    hp -= other.strength;
    invincible = 60;
    var oldX = phy_linear_velocity_x;
    var oldY = phy_linear_velocity_y;
    phy_speed_x = 0;
    phy_speed_y = 0;
    physics_apply_impulse(phy_position_x, phy_position_y, (phy_position_xprevious - phy_position_x) - oldX, (phy_position_yprevious - phy_position_y) - oldY);
    with(other){
        phy_speed_x = 0;
        phy_speed_y = 0;
    }
}
The enemy has no collision event with the player, just a hitbox event because the player has to be attacking and creating hitboxes in order to hurt enemies. Please let me know if you need to see more of the code. When a player touches an upgrade, an event runs in the upgrade object. If it collides with a player then obj_Player.strength += 1; Then it destroys itself.

Also something a little weird, why wont any show_debug_message() code run inside of that event when its set inside of the invincible section? I can see invincible is obviously being changed and the health subtraction is obviously happens. Makes no sense.
 
Last edited:
S

Snail Man

Guest
Your use of other seems to be correct; in the collision event, it refers to the object you're colliding with. However, I don't see where this code hurts the enemy: all this seems to do is hurt you, then stop the enemy.

Is that all the code in that event?
 

Erayd

Member
Yes, this only hurts the player. This is the code that runs when the player contacts the enemy, thereby hurting the player. My problem is that for some reason, raising the players strength changes how much damage the player is taking, which doesn't make sense.

EDIT: I just fixed it. I recently added some code relating to continual damage. Say you touch an enemy or object and stay on it somehow, then the collision event wont run again because you didn't stop touching it and then touch it again. Without some sort of continual damage code then you could walk on spikes after taking the first damage. I mistakenly used place_meeting to check for a collision in that code instead of instance_place. I needed the id of the object being collided because I was using the with statement and inside there I was reversing the other role because I didn't have the right id. My bad...
 
Last edited:
Top