J
jcg3729
Guest
I'm trying to do some basic ladder code without state (since I'm not very good writing them) and below is what I have (scroll to the end of second code posted).
While the current ladder code works my problem is the player 1) keeps bouncing on top of the ladder once they reach the top----bouncing even continues when I jump off the ladder onto the ground after touching said ladder AND 2) once the player hits the bottom after touching ladder they go right below the ground and fall through the ground platform.
I've played with it a little bit looking at other examples but I can't figure out what I'm doing wrong, which I'm sure it's an easy fix.
All help is appreciated if any.
Problem 1:
Problem 2:
Ladder object code:
Nothing
**Ladder object is layered above another object called "ladder mask" which has no code either.
Player object code:
Create
Step
Ladder code inside Step
While the current ladder code works my problem is the player 1) keeps bouncing on top of the ladder once they reach the top----bouncing even continues when I jump off the ladder onto the ground after touching said ladder AND 2) once the player hits the bottom after touching ladder they go right below the ground and fall through the ground platform.
I've played with it a little bit looking at other examples but I can't figure out what I'm doing wrong, which I'm sure it's an easy fix.
All help is appreciated if any.
Problem 1:
Problem 2:
Ladder object code:
Nothing
**Ladder object is layered above another object called "ladder mask" which has no code either.
Player object code:
Create
GML:
/// @description Player variables
grav = 0.6;
hsp = 0;
vsp = 0;
jumpspeed = 10;
movespeed = 5;
slidemax = 15;
slide = slidemax;
sliding = false;
Step
GML:
/// @description Insert description here
// You can write your code in this editor
//Get the player's input
var key_right = keyboard_check(vk_right);
var key_left = keyboard_check(vk_left);
var key_jump = keyboard_check_pressed(vk_space);
var key_run = keyboard_check(vk_shift);
var key_duck = keyboard_check(vk_down);
key_plat = keyboard_check(vk_space);
var onground = place_meeting(x, y + 1, o_solid);
//React to inputs
hsp = (key_right - key_left) * movespeed;
if vsp < 10
vsp += grav;
if onground and !key_duck
vsp = key_jump * -jumpspeed;
if (slide >= 0 and key_duck and key_jump and onground)
or (sliding) {
slide--;
slideanim = true;
hsp = image_xscale * 25;
sliding = true;
alarm[1] = 45;
if slide < 0 or !onground {
hsp = 0;
sliding = false;
slide = -1;
}
}
//run speed
if onground
if key_run and (key_left or key_right)
movespeed = 10;
else
movespeed = 5;
//Horizontal Collision
if place_meeting(x + hsp, y, o_solid) {
while !place_meeting(x + sign(hsp), y, o_solid)
x += sign(hsp);
hsp = 0;
}
x += hsp;
//Vertical Collision
if place_meeting(x, y + vsp, o_solid) {
while !place_meeting(x, y + sign(vsp), o_solid)
y += sign(vsp);
vsp = 0;
}
y += vsp;
//Wall Jumps
if (place_meeting(x+1,y,o_solid)) && (!place_meeting(x-1,y,o_solid))
{
if (key_jump) && (!place_meeting(x,y+1,o_solid))
{
vsp -= 12.4;
hsp -= 5;
}
}
if (place_meeting(x-1,y,o_solid)) && (!place_meeting(x+1,y,o_solid))
{
if (key_jump) && (!place_meeting(x,y+1,o_solid))
{
grav = normal_grav;;
vsp -= 12.4;
hsp += 5;
}
}
//Wall Slides Left
if (key_left = -1) && (vsp > 0) && (place_meeting(x-1,y,o_solid)) && (!place_meeting(x,y+1,o_solid))
{
if (vsp <= 11) && (vsp > 1.5) vsp -= 1;
if (vsp <= 11) && (vsp > 0) grav = .05;
}
if (key_left = -1 && (place_meeting(x-1,y,o_solid)) && (!place_meeting(x,y+1,o_solid)))
{
grav = normal_grav;
}
if (key_left = 0)
{
grav = normal_grav;
}
//Wall Slides Right
if (key_right = 1) && (vsp > 0) && (place_meeting(x+1,y,o_solid)) && (!place_meeting(x,y+1,o_solid))
{
if (vsp <= 16) && (vsp > 1.5) vsp -= 1;
if (vsp < 10) && (vsp > 0) grav = .05;
}
if (key_right = 1 && (place_meeting(x+1,y,o_solid)) && (!place_meeting(x,y+1,o_solid)))
{
grav = normal_grav;
}
if (key_right = 0)
{
grav = normal_grav;
}
// Climbing
if place_meeting(x,y,o_ladder) then //if on a ladder...
{
grav=0 //Don't fall
vsp=0
}
if (keyboard_check(vk_up))then{if place_meeting(x,y,o_ladder){vspeed=-4}}
if keyboard_check_released(vk_up) then{if place_meeting(x,y,o_ladder){vspeed=0}}
//Ladder Down
if (keyboard_check(vk_down)) then{if place_meeting(x,y,o_ladder){vspeed=4}}
if keyboard_check_released(vk_down) then{if place_meeting(x,y,o_ladder){vspeed=0}}
GML:
// Climbing
if place_meeting(x,y,o_ladder) then //if on a ladder...
{
grav=0 //Don't fall
vsp=0
}
if (keyboard_check(vk_up))then{if place_meeting(x,y,o_ladder){vspeed=-4}}
if keyboard_check_released(vk_up) then{if place_meeting(x,y,o_ladder){vspeed=0}}
//Ladder Down
if (keyboard_check(vk_down)) then{if place_meeting(x,y,o_ladder){vspeed=4}}
if keyboard_check_released(vk_down) then{if place_meeting(x,y,o_ladder){vspeed=0}}
Last edited by a moderator: