GameMaker 2 Platforms 1 horribly made dad joke

K

Kyle Rider

Guest
I have 2 platforms on the screen, the first one drawn works perfect. On the second one my player is carried the same way platform 1 is going. My head hurts, there must be an easy answer for this.

It may be that I am using a parent to control the platform and the children are just visual.

PARENT CODE
Code:
var c1, c2
hspd = dir * spd;   
x+=hspd;

//LEFT
if(dir == -1){                                                // if moving left
    c1 = -1;                                                // reset the collision tile checkers
    c2 = -1;
    c1 = tilemap_get_at_pixel(obj_Game.map, x - 60, y);                // check the left edge of the sprite
    c2 = tilemap_get_at_pixel(obj_Game.map,x,y);                // check below the left edge of the sprite, since ghosts dont like heights
    if(c1 == 9){                                // if there is something blocking the left or if there would be a fall to the left
        dir *= -1;                                            // change the direction
    }
}
//RIGHT 
else if(dir == 1)                                            // if moving right
{                                                            // Otherwise, check collision to the right
    c1 = -1                                                    // reset the collision tile checkers
    c2 = -1;
    c1 = tilemap_get_at_pixel(obj_Game.map,x + 60,y);                    // check the right edge of the sprite
    c2 = tilemap_get_at_pixel(obj_Game.map,x+12,y);    // check below the right edge of the sprite, since ghosts dont like heights
    if(c1 == 9){                                // if there is something blocking the right or if there would be a fall to the right
        dir *= -1;                                            // change the direction
    }
}
PLAYER CODE
Code:
x=x+hor_carry;

if place_meeting( x, y-25, par_platform)
{
    y = (y & ~31);
    if (key_left != 0)
    {
        sprite_index = spr_vrun;
    }
    else if (key_right != 0)
    {
        sprite_index = spr_vrun;
    }
    else if (key_jump !=0)
    {
        jumps +=1;
        sprite_index = spr_vjump;
    }else sprite_index = choose(spr_vidle);    // set the sprite to the idle sprite
    on_board = true;
    hor_carry = par_platform.hspd;
    hor_pfspeed = par_platform.spd;
    climbing = false;                // stop any climbing
    jump = false;                    // stop any jumping
    fall = false;                    // stop any falling
    jumps = 0;
}else hor_carry = 0; hor_pfspeed = 0;
 

FrostyCat

Redemption Seeker
Use instance_place() to get the colliding instance's ID, then work with that.
Code:
var platform = instance_place(x, y-25, par_platform);
if (platform != noone) {
  ...
 
  hor_carry = platform.hspd;
  hor_pfspeed = platform.spd;
}
When multiple instances of an object exist in the room, object.variable should never be referenced or set. In these situations where you need one specific instance, use a function that returns or a variable that contains an instance ID and put that on the left side of the dot.
  • instance_place() is the instance ID-oriented counterpart of place_meeting().
  • instance_position() is the instance ID-oriented counterpart of position_meeting().
  • All 4 collision_*() functions are instance ID-oriented.
And if you don't know the difference between "place" and "position", read this article.
 
K

Kyle Rider

Guest
Thank you very much and this article is now bookmarked.
 
T

Tset_Tsyung

Guest
Like Kyle, I too am gonna bookmark that article (might help with the issue I posted half an hour ago).

Also, like Nathan, I was disappointed by the lack of a 'dad' joke... lol
 
K

Kyle Rider

Guest
I was going to make the title a bad dad joke and caught myself before doing it.
 
K

Kyle Rider

Guest
FrostyCat said:
When multiple instances of an object exist in the room, object.variable should never be referenced or set. In these situations where you need one specific instance, use a function that returns or a variable that contains an instance ID and put that on the left side of the dot.
I really like your code and I tried implementing this with my mobs because I had been checking the collision in the enemy object.

Code:
//Getting hit by an enemy
var enemy_hit = instance_place(x, y, par_enemy);
if (enemy_hit != noone)
{
    if vhit = 0
    {
        dmg = enemy_hit.dmg;
        global.php = global.php - dmg;
        if (alarm[0] = -1) alarm = 15;
        sprite_index = spr_vhurt;
        image_index = 0;
        image_blend = make_color_hsv(0, 10, 125);
        state = states.hurt;
        vhit = 1;      
    }
}
My problem is that if I stay getting hurt my alarm doesn't function right and I never leave the hurt state.
 

FrostyCat

Redemption Seeker
You need to exit the hurt state and unset all the related flags as soon as the collision is gone.
Code:
if (enemy_hit != noone) {
  ...
} else {
  alarm[0] = -1;
  vhit = 0;
  state = states.normal;
}
 
K

Kyle Rider

Guest
This is my alarm event and I watch my alarm[0] in the GUI to test. it returns to -1.
Code:
vhit = 0;
image_blend = -1;
state = states.normal;
I will add the other variables to watch the event. I should add that if it is a fast mob and he has gone before the alarm it resets fine and everything returns to normal. This is if I stay on top of a mob.
 
Top