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

GameMaker Getting into difficult terrain (slow down player)

Axl Trauts

Member
Hi,

I want to alter speed of my player when entering difficult terrain, and return to normal (zero) when getting out of it. I am trying a collision check like instance_place but only works if I the player collides but not when gets out of the collision.

Below if the code that works. I've tried on the script a check if the collision give noone: "if i=noone" or just "else" then " global.var_player_spdmod=0 " and works, but overrides the condition "if i !=noone"

OBJ_PLAYER STEP EVENT (Requires a bit of improvement)
spdmod is a local variable that stores the global speed modifier value
Code:
spdmod = global.var_player_spdmod;
var hspd = 0;    var vspd = 0;
if y > __view_get( e__VW.YView, 0 )+40
{   vspd = -2;  }       // autonomous vertical scroll movement
if __view_get( e__VW.YView, 0 ) == 0
{   vspd = 0;   }

if keyboard_check(vk_left) and dead=0        {   if x>40 then hspd -= (6+spdmod);  }
if keyboard_check(vk_right) and dead=0    {   if x<room_width -40 then hspd += (6+spdmod);  }
if keyboard_check(vk_up) and dead=0        {   if y> __view_get( e__VW.YView, 0 )+40 then vspd -= (6+spdmod);  }
if keyboard_check(vk_down) and dead=0        {   if y<__view_get( e__VW.YView, 0 )+640 then vspd += (6+spdmod);  }
x += hspd;    y += vspd;
OBJ MUD STEP EVENT
Code:
scr_CheckSpeedMod(-4); // To be used on other terrain with movement alteration
SCRIPT scr_CheckSpeedMod
Code:
modifier = argument0;
//global.var_player_spdmod=0;
i=instance_place(x,y,obj_player_p1)

if i != noone
{    global.var_player_spdmod=modifier;    }
[/CODE[
 

Axl Trauts

Member
Update: It works great of there is only one slow terrain object, but when there´s more if fails. Now what I understand is that the false collision checks for every instance of the same object... uhm
 

Axl Trauts

Member
Update: I should have thought ot if: I used instance_place_list and on the obj_player instead of the terrain object and it worked BUT... in order to check a speed modifier with any instance of object that has it, I need to set a parent, like par_slow. The problem is the terrain I'm checking against already has a par_flammable that has code. Not every flammable object will affect speed and vice-versa so...

I need to think about creating a parent for all object/terrain states, such as par_states, where I can set slow=0/1 flammable=0/1, etc and check if theres a status variable and if it has anything. Back to think about it
 
Top