E
Edwin
Guest
Hey, it's me, Edwin again. yey
So basically a weird problem that I have is when player goes up via slope, and then right after it player collide with the wall, player get stuck.
It looks like this:
This is my Step Event code:
I think some variables like hspd, vspd aren't really matter here so you can declare them by yourself. But objects like parent_ground, object_ground, object_slope are more important:
So basically a weird problem that I have is when player goes up via slope, and then right after it player collide with the wall, player get stuck.
It looks like this:
This is my Step Event code:
Code:
/// Step Event
// Movement
if (keyboard_check(vk_right) && !keyboard_check(vk_left)) {
hspd = 9;
} else
if (keyboard_check(vk_left) && !keyboard_check(vk_right)) {
hspd = -9;
}
// Check not moving
if ((!keyboard_check(vk_right) && !keyboard_check(vk_left)) || (keyboard_check(vk_right) && keyboard_check(vk_left))) {
hspd = 0;
}
// Gravity
if (!place_meeting(x, y+1, parent_ground)) {
vspd += grav;
}
// Jumping
if (place_meeting(x, y+1, parent_ground)) {
if (keyboard_check_pressed(vk_up)) {
vspd = -20;
}
}
// Jump cancel
if (vspd < 0) {
if (keyboard_check_released(vk_up)) {
vspd *= 0.4;
}
}
// Variables
var hspd_final = hspd;
// Horizontal collision
horizontal_collision = instance_place(x+hspd_final, y, parent_ground);
if (horizontal_collision != noone) {
if (horizontal_collision.object_index == object_ground) {
while (!place_meeting(x+sign(hspd_final), y, horizontal_collision)) {
x += sign(hspd_final);
}
hspd_final = 0;
} else {
// Declare yplus
yplus = 0;
// Loop
while (place_meeting(x+hspd_final, y-yplus, parent_ground) && yplus <= abs(1*hspd_final)) {
yplus += 1;
}
y -= yplus;
while (place_meeting(x, y+1, parent_ground)) {
y -= 1;
}
}
}
// Down slope
down_slope = instance_place(x, y+1, parent_ground);
if (down_slope != noone && down_slope.object_index != object_ground) {
if (place_meeting(x, y+1, parent_ground)) {
yminus = abs(hspd_final);
while (place_meeting(x+hspd_final, y+yminus, parent_ground) && yminus != 0) {
yminus --;
}
y += yminus;
}
}
// Initialize horizontal speed
x += hspd_final;
// Vertical collision
if (place_meeting(x, y+vspd, parent_ground)) {
while (!place_meeting(x, y+sign(vspd), parent_ground)) {
y += sign(vspd);
}
vspd = 0;
}
// Initialize vertical speed
y += vspd;
- parent_ground is a parent object which childs are object_ground and object_slope;
- object_ground is a simple block object as basically in other infinite amount of games.
- object_slope is a slope with built-in precise collision.