S
Sarena
Guest
I'm creating a Platformer game and I've been having some collision issues when it comes to jumping. Whenever my character jumps and lands on a raised platform, they get stuck to it. The same happens if they start on a raised piece of ground and they jump or fall to the ground below. When they jump and land on a flat piece of ground that is level with where they started, they are fine. I'm not sure what's causing the collisions to be so finicky, but I've spent a few hours trying to debug my code.
I've been searching around a lot for answers to this question on the forums, and I haven't been able to find a solution that worked for me. I am using D&D, and just started using GameMaker about a month ago.
Here's what my code looks like currently in my objPlayer's Step Event:
(Keep in mind this is from the Live Preview since I'm using D&D)
And then the objPlayer's Create Event looks like this:
I'd appreciate any help I can get with this, thanks!
I've been searching around a lot for answers to this question on the forums, and I haven't been able to find a solution that worked for me. I am using D&D, and just started using GameMaker about a month ago.
Here's what my code looks like currently in my objPlayer's Step Event:
(Keep in mind this is from the Live Preview since I'm using D&D)
Code:
// Key Inputs
// Assign Variable
key_left = keyboard_check(vk_left) or keyboard_check(ord("A"));
key_right = keyboard_check(vk_right) or keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);
// Movement
// Declare Temp
var move = key_right - key_left;
// Assign Variable
hsp = move * walkspeed;
// Assign Variable
vsp = vsp + grv;
// Jump Collisions
// If Object At
var l5FF2BBF4_0 = instance_place(x, y + 1, objWall);
if ((l5FF2BBF4_0 > 0))
{
// If Variable
if(!(key_jump == 0))
{
// Assign Variable
vsp = -5;
}
}
// Horizontal Collisions
// If Object At
var l10CBD9A7_0 = instance_place(x + hsp, y, objWall);
if ((l10CBD9A7_0 > 0))
{
// Loop
while(true)
{
// If Object At
var l4E305BEB_0 = instance_place(x + sign(hsp), y, objWall);
if (!(l4E305BEB_0 > 0))
{
// Jump To Point
x = x + sign(hsp);
}
// Break
break;
}
// Assign Variable
hsp = 0;
}
// Jump To Point
x = x + hsp;
// Vertical Collisions
// If Object At
var l38BDDE9F_0 = instance_place(x, y + sign(vsp), objWall);
if ((l38BDDE9F_0 > 0))
{
// Loop
while(true)
{
// If Object At
var l5FB9B04A_0 = instance_place(x, y + sign(vsp), objWall);
if (!(l5FB9B04A_0 > 0))
{
// Jump To Point
y = y + sign(vsp);
}
// Break
break;
}
// Assign Variable
vsp = 0;
}
// Jump To Point
y = y + vsp;
Code:
// Assign Variable
hsp = 0;
vsp = 0;
grv = 0.1;
walkspeed = 4;