Ice Block

NightFrost

Member
What is your current movement code? The method compatible with most standard practises you see around here would be: firstly don't zero horizontal velocity between steps while standing on ice. This will make the player keep moving. Directional controls should not immediately change the velocity, but add only a small amount towards pressed direction, so the character slows down and then starts accelerating towards intended direction. Velocity should be clamped between negative and positive values of max speed after this adjustment, so you cannot limitlessly increase speed while on ice.
 

M.G.

Member
Thanks ..., my Movement code is this.


//Buttons

var rkey = keyboard_check(vk_right)
var lkey = keyboard_check(vk_left)


//Right

if (rkey)
{
hspd = spd
}


//Left

if (lkey)
{
hspd = -spd
}


//Stand

if((!rkey && !lkey)||(rkey && lkey))
{
hspd = 0
}
 

Roleybob

Member
There is very little to work on here.

In the game that I am currently working on I have ice sheets. The game is grid based, so when the player character starts moving, he/she (it? - haven't decided yet..) doesn't stop moving until reaching the next grid position. So basically when the player is in "move state", they keep moving until they end the step snapped to the grid, then they stop and change state to "idle" state and await further player input.

However, when the player character finishes their movement on an ice tile, instead of going to "idle" state, they stay in "move" state instead

From the very little information you have given, it seems that maybe you are making a platformer? A very simple method might be to check whether the player character is standing on ice and if they are then do not set hspd = 0
 

M.G.

Member
Yes it will be a Platformer ...,

This is the Ice Block Collision Code:

if place_meeting(x,y+vspd,obj_ice)
{
while(!place_meeting(x,y+sign(vspd),obj_ice))
{
y+=sign(vspd)
}
vspd = 0
}

I've already tried this Code:

if place_meeting(x,y+1,obj_ice)
{
friction = 0.2
}

But nothing happens there.
 

Japster

Member
Yes it will be a Platformer ...,

This is the Ice Block Collision Code:

GML:
if place_meeting(x,y+vspd,obj_ice)

{
    while(!place_meeting(x,y+sign(vspd),obj_ice))
    {
        y+=sign(vspd)
    }
    vspd = 0
}
Just wondering, as it's late and I'm tired, but in your 'while' loop, aren't you referencing VERTICAL speed variable, vspd, and adjusting the player's 'y' position down or up depending on vspd's sign? (which I'm assuming would also INSTANTLY set it if possible, were it correct? (ie. if approaching an ice_block vertically, loop until on the ice_block, but it will do all of this in 1 frame - speed permitting - but isn't this just the code that 'drops' the character onto the ice block instantly, if he's about to land on it?)

...aren't you intending to manipulate the player's X location/speed to enable sliding etc? - I'm a touch confused, but in my defence, I'm half-asleep! ;)

I'm assuming that you simply have to check below (x,y+1/2/3), and if it's an ice_block, simply retain speed, or 95% of it per frame(until a cutoff), etc? (i.e (hspd * 0.95) ...(and if NOT on a block, set or almost immediately slow xspd down to zero, if no direction pressed?):-

(I'm assuming 'sign' was used above in case of jumping up into a block, but again, friction wouldn't be affected normally, just running onto one would?) - Of course, I'm assuming that you've already got a variable to store / change 'x' speed, ie. xspd, so in this scenario, and you want to 'slip' you'd have to have it currently at non-zero to carry that slowly-decreasing speed onto the 'ice')...

GML:
if sign(vspd) == -1 exit;  // Jumping / moving UP?....

if place_meeting(x + hspd,y + vspd,obj_ice)
{
    while(!place_meeting(x + hspd,y + 1,obj_ice))
    {
        y += 1;
    }
    vspd = 0;
    hspd = (hspd * 0.95);  //only want to do this eg. once per frame, until you hit a minimum speed - ie. if speed is less than say, 1 or 2 pixels per frame, zero it?...
}
else
{
    xspd = 0;  // ...although you probably have code elsewhere to almost immediately slow down the player if NOT on ice / normal behaviour...  :)
}
 
Last edited:
Top