Author Topic: Ice Physics...  (Read 1905 times)

TheGamerGuy500

  • Cherry Eater
  • Posts: 62
  • I'm a gamer and a guy, video-game-music junkie...
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 46.0.2490.86 Chrome 46.0.2490.86
    • View Profile
    • TheGamerGuy500 HQ
  • Playstyle: Keyboard
Ice Physics...
« on: November 15, 2015, 12:24:40 PM »
It's that time of year, when snow and cold temperatures turn lakes into skating rinks.
I'd like to know how to get the ice physics from yuutuu into GM:studio.
But not just no ordinary ice physics though, I was thinking of the kind of physics for when you touch the ice, you get slippery controls even in the air, until you land on a non-ice block, if that's possible.
pls n thx
Pro tip: you gotta run and jump at the same time!
Notice: She doesn't stop spinning.

:KappaHD:

patrickgh3

  • Spike Dodger
  • Posts: 169
  • stay optimistic! :D
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 46.0.2490.80 Chrome 46.0.2490.80
    • View Profile
    • Github
  • Playstyle: Keyboard
Re: Ice Physics...
« Reply #1 on: November 15, 2015, 07:09:19 PM »
Hey, I implemented this real quick. The gist of it is I kept a state variable in the player called "slipping", which keeps track of if a player jumped off an ice block or not. I started off with my barebones project, and I marked my changes to the player's step event with comments starting with // PATRICK. Let me know if you have any questions I guess. :)

TheGamerGuy500

  • Cherry Eater
  • Posts: 62
  • I'm a gamer and a guy, video-game-music junkie...
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 46.0.2490.86 Chrome 46.0.2490.86
    • View Profile
    • TheGamerGuy500 HQ
  • Playstyle: Keyboard
Re: Ice Physics...
« Reply #2 on: November 15, 2015, 09:02:40 PM »
Hey, I implemented this real quick. The gist of it is I kept a state variable in the player called "slipping", which keeps track of if a player jumped off an ice block or not. I started off with my barebones project, and I marked my changes to the player's step event with comments starting with // PATRICK. Let me know if you have any questions I guess. :)

Um, yeah I have a question. I looked through the code, and your player step event is different in structure than mine. Do you think there's an easy way to combine it with Klazen's engine player object without a huge hassle? I'm just wondering, like, where would these code snippets even go?
Here's my player step event.
Code: [Select]
///Movement and Controls
var L,R,h;

// Check if pressing left/right || 左右のキー入力のチェック
L = keyboard_check_direct(global.leftbutton);
R = keyboard_check_direct(global.rightbutton);

// If pressing right, go right || 右ボタンを押していれば右
// If not pressing right, and pressing left, go left || 右ボタンを押していない状態で左ボタンを押していれば左
h = R;
if (h == 0) h = -L;
// If frozen, don't move || frozenに値が入っていれば行動禁止
if (frozen == true) h = 0;

// If we're moving || 左右の移動
if (h != 0) {
    // Set speed based on direction and maxSpeed || 走っている状態にする
    hspeed = maxSpeed*h;
    // 画像の左右を指定(負が入ると画像が左右反転する)
    //flip=(image_xscale!=h);
    xScale = h;
    //image_xscale = h;
   
    // Set the sprite to the running sprite || 走っている画像に変更
    sprite_index = sprPlayerRunning;
    image_speed = 0.5;
} else {
    // Set speed to zero || 直立状態にする
    hspeed = 0;
    // Set the sprite to the idle sprite || 直立画像に変更
    sprite_index = sprPlayerIdle;
    image_speed = 0.2;
}


if (!onPlatform) {
    // Set the sprite to jumping/falling if we're moving vertically and were not on a platform || ジャンプ・落下画像に変更
    if (vspeed < -0.05) {
        sprite_index = sprPlayerJump;
    }
    if (vspeed > 0.05) {
        sprite_index = sprPlayerFall;
    }
} else { // If we were on a platform, but we're not anymore, then set onPlatform to false || 動く台に乗ってる状態から解除された瞬間
    if (place_meeting(x,y+4,platform) == false) {
        onPlatform = 0;
    }
}

// Limit vspeed || vspeedが最大値を超えたら、最大値に固定
if (vspeed > maxVspeed) {
    vspeed = maxVspeed;
}

// If not frozen || frozenに値が入っていない(行動可能)
if (!frozen) {
    // Shoot || プレイヤーの攻撃
    if (keyboard_check_pressed(global.shotbutton)) {
        playerShoot();
    }
    // Jump || ジャンプ(押した)
    if (keyboard_check_pressed(global.jumpbutton)) {
        playerJump();
    }
    // Jump Release || ジャンプ(離した)
    if (keyboard_check_released(global.jumpbutton)) {
        playerVJump();
    }
}
Ours seem vastly different from one another.
« Last Edit: November 15, 2015, 09:06:02 PM by TheGamerGuy500 »
Pro tip: you gotta run and jump at the same time!
Notice: She doesn't stop spinning.

:KappaHD:

patrickgh3

  • Spike Dodger
  • Posts: 169
  • stay optimistic! :D
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 46.0.2490.80 Chrome 46.0.2490.80
    • View Profile
    • Github
  • Playstyle: Keyboard
Re: Ice Physics...
« Reply #3 on: November 15, 2015, 10:15:57 PM »
Ah, I'm assuming you started with the KS engine. I started with Yoyo's engine, which includes the yuuutu slip block logic, which I slightly modified. Here's a modified version of the code you just provided. It would have been nice to have your player step code from the start, now that I think about it.
Code: [Select]
///Movement and Controls
var L,R,h;

// Check if pressing left/right || 左右のキー入力のチェック
L = keyboard_check_direct(global.leftbutton);
R = keyboard_check_direct(global.rightbutton);

// If pressing right, go right || 右ボタンを押していれば右
// If not pressing right, and pressing left, go left || 右ボタンを押していない状態で左ボタンを押していれば左
h = R;
if (h == 0) h = -L;
// If frozen, don't move || frozenに値が入っていれば行動禁止
if (frozen == true) h = 0;

// PATRICK CHANGE - set slipping and slipval
var slipBlockTouching = instance_place(x,y+4*global.grav,oSlipBlock)
var blockTouching = instance_place(x,y+4*global.grav,block)
if slipBlockTouching != noone {
    slipping = true
    slipval = slipBlockTouching.slip
}
if (blockTouching != noone) and (slipBlockTouching == noone) {
    slipping = false
}

// If we're moving || 左右の移動
if (h != 0) {
    // PATRICK CHANGE - do either normal or slippery movement
    if not slipping {
        // Set speed based on direction and maxSpeed || 走っている状態にする
        hspeed = maxSpeed*h;
    }
    else {
        if (h == 1 and hspeed < maxSpeed) or (h == -1 and hspeed > -maxSpeed) {
            hspeed += slipval * h
        }
    }
    // 画像の左右を指定(負が入ると画像が左右反転する)
    //flip=(image_xscale!=h);
    xScale = h;
    //image_xscale = h;
   
    // Set the sprite to the running sprite || 走っている画像に変更
    sprite_index = sprPlayerRunning;
    image_speed = 0.5;
} else {
    // PATRICK CHANGE - do either normal or slippery stopping
    if not slipping {
        // Set speed to zero || 直立状態にする
        hspeed = 0;
    }
    else {
        if hspeed > 0 {
            hspeed -= slipval
            if hspeed <= 0 hspeed = 0
        }
        else if hspeed < 0 {
            hspeed += slipval
            if hspeed >= 0 hspeed = 0
        }
    }
    // Set the sprite to the idle sprite || 直立画像に変更
    sprite_index = sprPlayerIdle;
    image_speed = 0.2;
}


if (!onPlatform) {
    // Set the sprite to jumping/falling if we're moving vertically and were not on a platform || ジャンプ・落下画像に変更
    if (vspeed < -0.05) {
        sprite_index = sprPlayerJump;
    }
    if (vspeed > 0.05) {
        sprite_index = sprPlayerFall;
    }
} else { // If we were on a platform, but we're not anymore, then set onPlatform to false || 動く台に乗ってる状態から解除された瞬間
    if (place_meeting(x,y+4,platform) == false) {
        onPlatform = 0;
    }
}

// Limit vspeed || vspeedが最大値を超えたら、最大値に固定
if (vspeed > maxVspeed) {
    vspeed = maxVspeed;
}

// If not frozen || frozenに値が入っていない(行動可能)
if (!frozen) {
    // Shoot || プレイヤーの攻撃
    if (keyboard_check_pressed(global.shotbutton)) {
        playerShoot();
    }
    // Jump || ジャンプ(押した)
    if (keyboard_check_pressed(global.jumpbutton)) {
        playerJump();
    }
    // Jump Release || ジャンプ(離した)
    if (keyboard_check_released(global.jumpbutton)) {
        playerVJump();
    }
}

The object oSlipBlock should be solid and have block as its parent. it should also have the variable "slip" set in its create event; the default value in yuuutu is 0.2.

Also, in the create event of the player, you should define these variables:
Code: [Select]
slipping = false
slipval = 0

You should look through the player step code and find all the comments where I changed something, and get the gist of how it works. You might have to modify it a little, I'm not sure.

EDIT: here's the gist of how my changes work:
1. In the player object, keep track of a variable called "slipping", which keeps track of whether the player should currently be slipping or not. To do this, we set it to true if we detect we're standing on a slippery block, and false if we're standing on a normal block. This way it remembers the state until we next touch a ground. This is the first code block I added towards the top.

2. Modify the player horizontal movement and stopping behavior to each have alternate slipping behaviors. I added if statements depending on the slipping variable, and copied the slip behaviors from the yuuutu engine. These are the second and third code blocks I modified.

3. Also keep track of a variable called "slipval", which keeps track of the "slip" variable of the last slippery block the player touched. The yuuutu slippery block behavior didn't need this because the player could just re-check the slip value of the block it was standing on, but since we're in the air sometimes we need to keep track of it. This explanation isn't the clearest, but I hope it helps a little.
« Last Edit: November 15, 2015, 10:34:54 PM by patrickgh »

TheGamerGuy500

  • Cherry Eater
  • Posts: 62
  • I'm a gamer and a guy, video-game-music junkie...
  • OS:
  • Mac OS X 10.9.5 Mac OS X 10.9.5
  • Browser:
  • Chrome 46.0.2490.86 Chrome 46.0.2490.86
    • View Profile
    • TheGamerGuy500 HQ
  • Playstyle: Keyboard
Re: Ice Physics...
« Reply #4 on: November 16, 2015, 03:52:22 PM »
I'll see to it. I think that explanation and code modification is pretty much all I needed. Thanks a bundle, mate!
Pro tip: you gotta run and jump at the same time!
Notice: She doesn't stop spinning.

:KappaHD: