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

Legacy GM Ledge grab code, What did I do wrong?

K

Kaizer_White

Guest
I feel like your vspd and hspd are constantly being set to 0.

So this is probably along the lines of what is happening:

1) You are increasing your player speed at the start of the step event
2) You are doing collision checks and moving your player in the middle of the event
3) You are now constantly setting hspd and vspd to 0, when colliding. That is why the state gets changed to 2 forever; you're in the grabbing state.

If you're able to move as though you were in the walking state, that means that:
1) your states are set up wrongly, or:
2) in your collision code (or somewhere else) you are constantly setting your state to be the walking state, and then it's getting reset to the ledge state etc..
The hspd and vspd aere constantly getting set to zero... shouldn't they be?
 

Nux

GameMaker Staff
GameMaker Dev.
Well, yeah. But you must set them to 0 before you check for collisions. Otherwise the player will start to move and then stop constantly.
 
K

Kaizer_White

Guest
Well, yeah. But you must set them to 0 before you check for collisions. Otherwise the player will start to move and then stop constantly.
well the moving is smooth no problems there. Its just that once we grab a ledge, the ledge grab state machine doesn't seem to work likei its meant to. Should i post my collision machine just in case its the problem?

///move (collision_object)

var collision_object = argument0

// Horizontal Collisions
if (place_meeting(x + hspd, y, obj_wall)) {
while (!place_meeting(x + sign(hspd), y, obj_wall)) {
x += sign(hspd);
}
hspd = 0;
}
x += hspd
// Vertical Collisions

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

Nux

GameMaker Staff
GameMaker Dev.
I can't see anything wrong with the code you've sent.

What's the bigger picture?
How are you changing state?
What does your state machine look like?
What does your step event look like?
 
K

Kaizer_White

Guest
I can't see anything wrong with the code you've sent.

What's the bigger picture?
How are you changing state?
What does your state machine look like?
What does your step event look like?
/// Control Player State

script_execute (move_state)

thats the step event...


this is the move state:

/// move_state

// Movement, Collision and Gravity

// Instance Variables

var up = (keyboard_check (ord ("W")))
var left = (keyboard_check (ord ("A")))
var down = (keyboard_check (ord ("S")))
var right = (keyboard_check (ord ("D")))
var space = (keyboard_check (vk_space))
var space_released = (keyboard_check_released (vk_space))

// Gravity

if (!place_meeting (x, y + 1, obj_wall)) {
vspd += grav;
if (space_released and vspd < -6) {
vspd = -6;
}
} else {
vspd = 0;

// Jumping Code

if (space) {
vspd = -16;
}
}

// Movement

if (right) {
hspd = spd;
}

if (left) {
hspd = -spd;
}

if (hspd !=0) {
image_xscale = sign(hspd);
}

// Friction

if (!right and !left) {
hspd = 0;
}

move (obj_wall)

// Check for ledge grab state


var height = bbox_bottom-bbox_top // get height of player

// get flags
var falling = vspd > 0 // falling
var no_wall = !place_meeting (x+image_xscale, y-height, obj_wall) // check at top of player
var is_wall = place_meeting (x+image_xscale, y, obj_wall)

if (falling and no_wall and is_wall)
{
// set speeds to 0
hspd = 0;
vspd = 0;

// Move against the ledge
while (!place_meeting (x+image_xscale, y, obj_wall))
{
x += image_xscale
}

// Make sure we are the right height
while (place_meeting (x+image_xscale, y - 30, obj_wall))
{
y-= .1;
}

state = ledge_grab_state
}






This is the ledge grab:

/// ledge_grab_state

var space_key = (keyboard_check (vk_space))
var s_key = (keyboard_check (ord ("S")))

if (s_key) {
state = move_state;
}

if (space_key) {
state= move_state
vspd= -16;
}

This is the collision:

///move (collision_object)

var collision_object = argument0

// Horizontal Collisions
if (place_meeting(x + hspd, y, obj_wall)) {
while (!place_meeting(x + sign(hspd), y, obj_wall)) {
x += sign(hspd);
}
hspd = 0;
}
x += hspd
// Vertical Collisions

if (place_meeting(x, y + vspd,obj_wall)) {
while (!place_meeting(x, y + sign(vspd), obj_wall)) {
y += sign(vspd);
}
vspd = 0;
}
y += vspd
 
  • Like
Reactions: Nux

Nux

GameMaker Staff
GameMaker Dev.
GREAT!

change:
Code:
script_execute (move_state)
to:
Code:
script_execute (state)
 
K

Kaizer_White

Guest
GREAT!

change:
Code:
script_execute (move_state)
to:
Code:
script_execute (state)
IT WORKED! THANKS FOR THE HELP!







... I did something stupid didn't I....



T -T Sorry.....
 

Nux

GameMaker Staff
GameMaker Dev.
... I did something stupid didn't I....
LMAO yeah but it's okay, I've done something similar before, don't worry!

I'm glad I could help.
I knew the code was supposed to work >8)

P.s. But yeah, try follow a problem through like a computer, that way it's easier to figure out where things are going wrong. I could see that was the problem because I thought "well, if the move_state is getting executed every step, then where's the ledge_grab_state getting executed?".
 
K

Kaizer_White

Guest
LMAO yeah but it's okay, I've done something similar before, don't worry!

I'm glad I could help.
I knew the code was supposed to work >8)

P.s. But yeah, try follow a problem through like a computer, that way it's easier to figure out where things are going wrong. I could see that was the problem because I thought "well, if the move_state is getting executed every step, then where's the ledge_grab_state getting executed?".

Thanks for all the help Nux, honestly couldn't have spotted that without you! Next time I have a problem I'll work try work through it and not take up too much of your time!


THANKS A MILLION! :D
 
  • Like
Reactions: Nux
Top