1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Welcome to Lake Valor!
    Catch, train, and evolve Pokémon while you explore our community. Make friends, and grow your collection.

    Login or Sign Up

Game Maker Platforming Engine Help

Discussion in 'Creative Zone' started by Nova Ozuka, Apr 22, 2018.

  1. Nova Ozuka

    Nova Ozuka Hex Maniac

    Joy
    (Togepi)
    Level 25
    Joined:
    Jan 11, 2017
    Posts:
    448
    PokéPoints:
    ₽2,366.3
    Right! So I decided to try to make a somewhat Megaman/Metroid styled Platforming game in Game Maker. So far I managed to copy a basic engine, but I need help coding some actions for the player character. If anyone can help, let me know!

    The first things I need help with are coding the run action to the 'a' key as well as coding a wall jump.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Getus

    Getus The Senate

    Ky
    (Kyogre Egg)
    Level 18
    Joined:
    Apr 4, 2016
    Posts:
    1,166
    PokéPoints:
    ₽111.6
    Philosopher's CowlReaper Cloth ★★★Psychium Z ★★★★Great Ball ★★Cooler Gary Oak ★★★★★
    if keyboard_check(ord("D"))
    {
    x=x+4;
    }

    Not familiar with game maker, but some stuff I looked up seems to point towards this code working, although might be easier if you write this in the object's create event:

    D = keyboard_check(ord("D"))
    spd=4

    then you can write the code more easily like this

    if (D)
    {
    x+=spd
    }

    Hope this helps, also replace the D references with A and set the spd= to a number that creates the velocity you want
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    Nova Ozuka likes this.
  3. Nova Ozuka

    Nova Ozuka Hex Maniac

    Joy
    (Togepi)
    Level 25
    Joined:
    Jan 11, 2017
    Posts:
    448
    PokéPoints:
    ₽2,366.3
    That helps fix the run code I already tried. Now it looks like this:

    //Get player's input
    key_run = keyboard_check(ord("A"))

    //React to inputs
    if (key_run)
    {
    hsp = move * movespeed * 2;
    }

    It seems to work too. Even if the physics don't work how I'd like them too, it at least fits my first project, and I can always change the run speed multiplier later.

    Okay, so I still need the wall jump code and a wall slide code to go with it. Something like you hold the arrow key to cling to the wall, and then press the jump button to jump off it like in Mega Man games. Unlike the run code, I have no idea where to begin.
     
    #3 Apr 22, 2018
    Last edited by a moderator: Apr 24, 2018
    Getus likes this.
  4. Getus

    Getus The Senate

    Ky
    (Kyogre Egg)
    Level 18
    Joined:
    Apr 4, 2016
    Posts:
    1,166
    PokéPoints:
    ₽111.6
    Philosopher's CowlReaper Cloth ★★★Psychium Z ★★★★Great Ball ★★Cooler Gary Oak ★★★★★
    I've kinda used something like this before in Unreal Engine, used line tracing and stuff. It's incredibly complicated and I couldn't get it working properly. Not sure how it would work via Game Maker though but I'll give it a look and see if I can find something that may help you, in the mean time see if you can't find something via youtube or the gamemaker forums (I think they exist)
     
  5. Nova Ozuka

    Nova Ozuka Hex Maniac

    Joy
    (Togepi)
    Level 25
    Joined:
    Jan 11, 2017
    Posts:
    448
    PokéPoints:
    ₽2,366.3
    Unfortunately, I can't watch Youtube at home. I have to do it at the library, and anything I learn through that I'll probably forget on the way home. I would need to be able to apply it right away. What I'm trying to do is find a line of code that I can add to the engine I've put together so far. So far, finding that code in the forums is like finding a needle in a haystack.

    I'd try to figure it out myself, but coding is almost like a foreign language to me, as proven by my first attempt at coding running in my game. I didn't know I needed ord("A") inside the keyboard_check() instead of just keyboard_check(a), and I didn't really have a quick means of finding out what exactly needed to be there to make the code work without turning to the internet, so I winged it. I came pretty close to being exactly right the first time, I admit, but without knowing exactly what to put there, it didn't work at all.

    @Getus Any idea how to devide variables? I can't seem to figure it out. Halving the variable for vertical speed might be all that stands between me and completing my wall slide code and testing my own wall jump code.

    Edit: Nvm, I looked it up
     
    #5 Apr 23, 2018
    Last edited by a moderator: Apr 24, 2018
  6. Getus

    Getus The Senate

    Ky
    (Kyogre Egg)
    Level 18
    Joined:
    Apr 4, 2016
    Posts:
    1,166
    PokéPoints:
    ₽111.6
    Philosopher's CowlReaper Cloth ★★★Psychium Z ★★★★Great Ball ★★Cooler Gary Oak ★★★★★
    time_str = string(time div 60);

    In this code it is using "div" to divide the string called time by 60. Essentially if you were wanting to divide your velocity it would be

    velocity_float=float(velocity div 10) I think this is it? Again not certain, but give it a try. Whatever your movement speed variable is called use the same format but with those names and variable type then div by the amount you want.
     
  7. Nova Ozuka

    Nova Ozuka Hex Maniac

    Joy
    (Togepi)
    Level 25
    Joined:
    Jan 11, 2017
    Posts:
    448
    PokéPoints:
    ₽2,366.3
    SO far since I posted, I got my wall slide code to work, but not as intended by using vsp = vsp / 2 I was able to get the player to slow down against a wall for a moment, but I wasn't able to get it to stay slowed down. Arguably, the line that resets the player state may be to blame as the line reads if (vsp = 0) then state = "normal", but that should only apply if the player isn't moving up or down.

    The first problem is that I can't get the speed to remain slowed until the player is touching the ground. Maybe something like vsp = 0.5 would work better? I might try that, but idk.

    Second problem is that I can't seem to get the wall jump to work either. This might be caused by the same issue as the wall slide. The wall jump code is set to work the player's while state is "wall_slide_l" or "wall_slide_r". When holding left or right while moving vertically along a wall, the slide code is supposed to trigger the respective state while slowing down the player's speed until they either release or jump. Somehow, neither state is working.

    Well I tried a different line of code that had almost the exact opposite of the original.

    if (vsp < 10 and state = "normal") vsp += grav;
    if (vsp < 10 and state = "wall_slide_r" or state ="wall_slide_l") vsp = 0.5;

    Instead of triggering only on initial contact like before, the slowed fall speed is always active even when state should = "normal".

    Here's the full code so far.

    //Get the player's input
    key_right = keyboard_check(vk_right);
    key_left = -keyboard_check(vk_left);
    key_down = keyboard_check(vk_down);
    key_enter = keyboard_check(vk_enter);
    key_jump = keyboard_check_pressed(vk_space);
    key_run = keyboard_check(ord("A"));
    key_attack = keyboard_check(ord("S"));
    key_special = keyboard_check(ord("D"));
    key_action = keyboard_check(ord("F"));

    //Reset Player's state
    if (key_down = false and vsp = 0) then state = "normal" else state = "crouch"
    if (vsp < 0) then state = "normal"

    //React to inputs
    move = key_left + key_right;
    hsp = move * movespeed;
    if (vsp < 10 and state = "normal") vsp += grav;
    if (vsp < 10 and state = "wall_slide_r" or state = "wall_slide_l") vsp = 0.5;

    if (place_meeting(x,y+1,obj_wall))
    {
    vsp = key_jump * -jumpspeed
    }

    if(key_run)
    {
    hsp = move * movespeed * 2
    }

    if (key_jump)
    {
    while state = "wall_slide_r"
    {
    state = "normal"
    vsp = -7;
    hsp = -7;
    }
    while state = "wall_slide_l"
    {
    state = "normal"
    vsp = -7;
    hsp = 7;
    }
    }

    //Horizontal Collision
    if (place_meeting(x+hsp,y,obj_wall))
    {
    while(!place_meeting(x+sign(hsp),y,obj_wall))
    {
    x += sign(hsp);
    }
    hsp = 0;
    }
    x += hsp;

    if (place_meeting(x+hsp,y,obj_wall))
    {
    while vsp > 0 or vsp < 0 and (key_right)
    {
    state = "wall_slide_r"
    }
    }

    //Vertical Collision
    if (place_meeting(x,y+vsp,obj_wall))
    {
    while(!place_meeting(x,y+sign(vsp),obj_wall))
    {
    y +=sign(vsp);
    }
    vsp = 0;
    }
    y += vsp;
     
    #7 Apr 23, 2018
    Last edited by a moderator: Apr 24, 2018
  8. Nova Ozuka

    Nova Ozuka Hex Maniac

    Joy
    (Togepi)
    Level 25
    Joined:
    Jan 11, 2017
    Posts:
    448
    PokéPoints:
    ₽2,366.3
    Alright, so I got a working wall slide now, but I still can't quite get my wall jump to work properly. No matter what hsp is set to, it only launches the player straight up regardless of if they're sliding down the walI can fix the issue where they don't need to wallslide to jump by using states, but the problem where no horizontal movement occurs at all needs fixing. I tried a couple of things already, but I can't figure it out. THe player is not a Megaman character, therefore they should need two walls to propel themselves upward. Even if they were, they still would have to push themselves off the wall before going back to the wall.

    //Get the player's input
    key_right = keyboard_check(vk_right);
    key_left = -keyboard_check(vk_left);
    key_down = keyboard_check(vk_down);
    key_enter = keyboard_check(vk_enter);
    key_jump = keyboard_check_pressed(vk_space);
    key_run = keyboard_check(ord("A"));
    key_attack = keyboard_check(ord("S"));
    key_special = keyboard_check(ord("D"));
    key_action = keyboard_check(ord("F"));

    //React to inputs
    move = key_left + key_right;
    hsp = move * movespeed;
    if (vsp < 10) vsp += grav;

    if (place_meeting(x,y+1,obj_wall))
    {
    vsp = key_jump * -jumpspeed
    }

    if(key_run)
    {
    hsp = move * movespeed * 2
    }

    //Horizontal Collision
    if (place_meeting(x+hsp,y,obj_wall))
    {
    while(!place_meeting(x+sign(hsp),y,obj_wall))
    {
    x += sign(hsp);
    }
    hsp = 0;
    }
    x += hsp;

    //Vertical Collision
    if (place_meeting(x,y+vsp,obj_wall))
    {
    while(!place_meeting(x,y+sign(vsp),obj_wall))
    {
    y +=sign(vsp);
    }
    vsp = 0;
    }
    y += vsp;

    //Wallsliding
    if (key_left = -1) && (vsp > 0) && (place_meeting(x-1,y,obj_wall)) && (!place_meeting(x,y+1,obj_wall))
    {
    if (vsp <= 11) && (vsp > 1.5) vsp -= 0.2;
    }

    if (key_right = 1) && (vsp > 0) && (place_meeting(x+1,y,obj_wall)) && (!place_meeting(x,y+1,obj_wall))
    {
    if (vsp <= 16) && (vsp > 1.5) vsp -= 0.2;
    }

    //Wall Jump
    if (place_meeting(x-1,y,obj_wall)) and (!place_meeting(x+1,y,obj_wall))
    {
    if (key_jump) and (!place_meeting(x,y+1,obj_wall))
    {
    vsp = -7;
    hsp -= 5;
    }
    }

    if (place_meeting(x+1,y,obj_wall)) and (!place_meeting(x-1,y,obj_wall))
    {
    if (key_jump) and (!place_meeting(x,y+1,obj_wall))
    {
    vsp = -7;
    hsp += 5;
    }
    }
     
  9. Nova Ozuka

    Nova Ozuka Hex Maniac

    Joy
    (Togepi)
    Level 25
    Joined:
    Jan 11, 2017
    Posts:
    448
    PokéPoints:
    ₽2,366.3
    Noticed one flaw with the code that I'm glad I caught. Even if the Wall Jump worked the way it should've, it's coded in a way that would make the player move until they hit another wall while increasing in speed. That being said, I still have no idea why it isn't pushing the player off the wall, and I still have nobody helping me figure out why this part of the code isn't working the way it should, which is kind of defeating the purpose of this thread.
     
  10. Nova Ozuka

    Nova Ozuka Hex Maniac

    Joy
    (Togepi)
    Level 25
    Joined:
    Jan 11, 2017
    Posts:
    448
    PokéPoints:
    ₽2,366.3
    Alright, so I've been posting on the GM forums. Turns out I needed to swap the positive and negative hsp values for the code to have any effect. But it wasn't that simple. The code overwrites hsp each step, so I had to make two new variables to act as a timer so that they would keep hsp the same value for longer than the first step. That being said, I now have a working wall jump code. Now I need help coding the HUD.

    The HUD I'm using for the first game uses an upgradable Zelda style health bar, but measured with cupcakes where each cupcake = 2 points of health. It also will contain an ammo/energy/magic meter, a coin counter, and a clock that times how long you take in each level. The main things I need right away to continue are the Zelda style health bar and the meter. Then I can work on coding the enemies, a few actions, and some of the collectables.
     

Share This Page