Objects Behaving differently even though they are the same

A

Arj72

Guest
I've been working on a 2.5D platformer game for about a week now and I've run into an issue. The main character encounters enemies, called Nuggets, that just walk left in right within designated zones and are supposed to hurt the player when you walk in to them. You can kill them by jumping on them. My problem I am encountering is some of the enemies function properly, and some just walk right by the player, never causing damage. Here is the two different codes, the first one for killing the enemy, by triggering an alarm that destroys it, and the second is where it hurts the player, before once again being destroyed.

if (place_meeting(x,y,obj_player))

{
if (obj_player.y < y-6)
{
with (instance_nearest(x,y, Obj_Nugget))
alarm[0]= .044*room_speed
sprite_index= (Spr_NuggetDie);}
}
----------------------------------------------------------
if (place_meeting(x,y,obj_player))

{
if (obj_player.y >= Obj_Nugget.y)
{
with (instance_nearest(x,y, Obj_Nugget))
sprite_index= Spr_NuggetDie
global.phealth -= 1
alarm[0] = .044*room_speed;}
}
 
W

WinuX

Guest
I just assume that the 2 codes above are in Obj_Nugget.

You are refering to Obj_Nugget in your Code a lot, that means you refering to all of them not just the one the player collides with.

Try putting the code below into the Nuggets step event.

if (place_meeting(x,y,obj_player))
{
if (other.y < y-6)
{
alarm[0]= .044*room_speed;
sprite_index= (Spr_NuggetDie);
}
}
----------------------------------------------------------
if (place_meeting(x,y,obj_player))
{
if (other.y >= y)
{
sprite_index= Spr_NuggetDie;
global.phealth -= 1;
alarm[0] = .044*room_speed;
}
}

The "other" keyword is just refering to the other instance involved in the collision (obj_player).
 
A

Arj72

Guest
I just assume that the 2 codes above are in Obj_Nugget.

You are refering to Obj_Nugget in your Code a lot, that means you refering to all of them not just the one the player collides with.

Try putting the code below into the Nuggets step event.

if (place_meeting(x,y,obj_player))
{
if (other.y < y-6)
{
alarm[0]= .044*room_speed;
sprite_index= (Spr_NuggetDie);
}
}
----------------------------------------------------------
if (place_meeting(x,y,obj_player))
{
if (other.y >= y)
{
sprite_index= Spr_NuggetDie;
global.phealth -= 1;
alarm[0] = .044*room_speed;
}
}

The "other" keyword is just refering to the other instance involved in the collision (obj_player).

Thanks! I'll try that now and let you know how it works.
 
A

Arj72

Guest
I just assume that the 2 codes above are in Obj_Nugget.

You are refering to Obj_Nugget in your Code a lot, that means you refering to all of them not just the one the player collides with.

Try putting the code below into the Nuggets step event.

if (place_meeting(x,y,obj_player))
{
if (other.y < y-6)
{
alarm[0]= .044*room_speed;
sprite_index= (Spr_NuggetDie);
}
}
----------------------------------------------------------
if (place_meeting(x,y,obj_player))
{
if (other.y >= y)
{
sprite_index= Spr_NuggetDie;
global.phealth -= 1;
alarm[0] = .044*room_speed;
}
}

The "other" keyword is just refering to the other instance involved in the collision (obj_player).
It seems that with that code now the player's health is deducted even if I fall onto the Nugget. But all the Nuggets were doing damage this time.
 
W

WinuX

Guest
make an variable called dying or something like that and set it on true when the Nugget gets killed

something like that


CREATE:
dying = false;


STEP:

if (place_meeting(x,y,obj_player) && !dying)
{
if (other.y < y-6)
{
dying = true;
alarm[0]= .044*room_speed;
sprite_index= (Spr_NuggetDie);
}
}
----------------------------------------------------------
if (place_meeting(x,y,obj_player) && !dying)
{
if (other.y >= y )
{
dying = true;
sprite_index= Spr_NuggetDie;
global.phealth -= 1;
alarm[0] = .044*room_speed;
}
}
 
A

Arj72

Guest
make an variable called dying or something like that and set it on true when the Nugget gets killed

something like that


CREATE:
dying = false;


STEP:

if (place_meeting(x,y,obj_player) && !dying)
{
if (other.y < y-6)
{
dying = true;
alarm[0]= .044*room_speed;
sprite_index= (Spr_NuggetDie);
}
}
----------------------------------------------------------
if (place_meeting(x,y,obj_player) && !dying)
{
if (other.y >= y )
{
dying = true;
sprite_index= Spr_NuggetDie;
global.phealth -= 1;
alarm[0] = .044*room_speed;
}
}
That didn't work either... I must have had some weird original coding somewhere because the Nuggets will die now, but it still hurts the player to jump on them too.
 
W

WinuX

Guest
Could you try this it should work.

if (place_meeting(x,y,obj_player))
{
//Jump
if (other.y < y-6 && !dying)
{
alarm[0]= .044*room_speed;
sprite_index= (Spr_NuggetDie);
dying = true;
}

//Walk in
if (other.y >= y && !dying)
{
sprite_index= Spr_NuggetDie;
global.phealth -= 1;
alarm[0] = .044*room_speed;
dying = true;
}
}
 
A

Arj72

Guest
Could you try this it should work.

if (place_meeting(x,y,obj_player))
{
//Jump
if (other.y < y-6 && !dying)
{
alarm[0]= .044*room_speed;
sprite_index= (Spr_NuggetDie);
dying = true;
}

//Walk in
if (other.y >= y && !dying)
{
sprite_index= Spr_NuggetDie;
global.phealth -= 1;
alarm[0] = .044*room_speed;
dying = true;
}
}

For whatever reason it isn't working, the player is still taking damage from jumping on them .
 
W

WinuX

Guest
Can you try the code below.
When you walk or jump into the nugget a popup message should appear.
If you Jump on a Enemy it will say "Jumped on Enemy".
If you walk into one it will say "Walked into an Enemy".

When the Popups are correct about what is happening, then something is off somewhere else.

if (place_meeting(x,y,obj_player))
{
//Jump
if (other.y < y-6 && !dying)
{
alarm[0]= .044*room_speed;
sprite_index= (Spr_NuggetDie);
dying = true;
show_message("Jumped on enemy");
}

//Walk in
if (other.y >= y && !dying)
{
sprite_index= Spr_NuggetDie;
global.phealth -= 1;
alarm[0] = .044*room_speed;
dying = true;
show_message("Walked in Enemy");
}
}
 
A

Arj72

Guest
Can you try the code below.
When you walk or jump into the nugget a popup message should appear.
If you Jump on a Enemy it will say "Jumped on Enemy".
If you walk into one it will say "Walked into an Enemy".

When the Popups are correct about what is happening, then something is off somewhere else.

if (place_meeting(x,y,obj_player))
{
//Jump
if (other.y < y-6 && !dying)
{
alarm[0]= .044*room_speed;
sprite_index= (Spr_NuggetDie);
dying = true;
show_message("Jumped on enemy");
}

//Walk in
if (other.y >= y && !dying)
{
sprite_index= Spr_NuggetDie;
global.phealth -= 1;
alarm[0] = .044*room_speed;
dying = true;
show_message("Walked in Enemy");
}
}
Thank you for the help, but I think I figured it out. Because I have such a weird system where an alarm gives the enemy enough time to play the death animation, having the code you gave me under step made it instantly check for a collision again before the nugget could die, and the player was no longer jumping on it. I put it back under collision and am hoping that will work.
 
Top