SOLVED Object not moving in platformer

obj_player won’t fall, jump, or move left/right. I have fixed error that I’ve found. I have set variables for grav, spd, jspd, hspd, and vspd. The only thing left is the code.
Here is the code
Code:
/// Platform physics

var rkey = keyboard_check(vk_right);
var lkey = keyboard_check(vk_left);
var jkey = keyboard_check(vk_up);

// Check for ground
if (place_meeting(x, y+1, obj_platform)) {
    vspd = 0;
   
    // Jumping
    if (jkey) {
        vspd = -jspd;
    }
}   else {
    // Gravity
    if (vspd < 10) {
        vspd += grav;
    }
}

// Moving right
if (rkey) {
    hspd = spd
}

// Moving left
if (lkey) {
    hspd = -spd;
}

// Check for not moving
if ((!rkey && !lkey) || (rkey && lkey)) {
    hspd = 0;
}

// Horiontal Collisions
if (place_meeting(x+hspd, y, obj_platform)) {
    while (!place_meeting(x+sign(hspd), y, obj_platform)) {
        x+= sign(hspd);
    }
    hspd = 0;
}

// Move horizonally
x += hspd;

// Vertical Collisions
if (place_meeting(x, y+vspd, obj_platform)) {
    while (!place_meeting(x, y+sign(vspd), obj_platform)) {
        y += sign(vspd);
    }
    vspd = 0;
}

// Move vertically
y += vspd;
 
Last edited:

TheouAegis

Member
Just to verify, what is in your Create Event and any other events in this object? I doubt it will reveal anything telling, since I recognize the code you are using, but who knows.

Also, is this the ONLY object in the room, other than obj_platform? Try testing it in a room with no objects other than this one. Does the object immediately fall? If so, add an obj_platform into the room some way below it, but not directly below it. Does the object fall down and land on the platform? If so, can you then move left & right or and jump on the platform? If yes, start adding any other objects to the room one at a time until the room bugs out.
 
This is in the create event:
GML:
/// Initialize variables
grav = 1;
spd = 4;
jspd = 12;
hspd = 0;
vspd = 0;
also, I tried to recreate the glitch but nothing happened. I tried making platforms merge into each other, adding as many as I could, and even recreating the original room, but with no luck. This makes me think that it has to do with something in the room settings, but I can’t figure out what I changed to make it behave like that.
 
Last edited:

TheouAegis

Member
This is in the create event:
GML:
/// Initialize variables
grav = 1;
spd = 4;
jspd = 12;
hspd = 0;
vspd = 0;
also, I tried to recreate the glitch but nothing happened. I tried making platforms merge into each other, adding as many as I could, and even recreating the original room, but with no luck. This makes me think that it has to do with something in the room settings, but I can’t figure out what I changed to make it behave like that.
Make sure you did not enable Physics in the room nor in the object.
 
Top