EDIT: Fixed Jumping Problem, Having Collision Problems! Changed Source Code below!
GMK: LinkI'm at work and decided to create a Platformer in my down time. Well, since I'm not at home, I don't have any of my source code and notes that I would usually have, so I'm going to ask 64D this rather embarrassing question: How do I get my damned character to jump? Here's the two scripts that I'm sure are screwing things up, both run in the Step Event:scr_plr_movement:
//Horizontal Movement
if keyboard_check(vk_right) = true
{
if hspeed < max_speed{hspeed += accel_speed;}
else {hspeed = max_speed;}
}
else if keyboard_check(vk_left) = true
{
if hspeed > -max_speed{hspeed -= accel_speed;}
else {hspeed = -max_speed;}
}
else if keyboard_check(vk_left) = false and keyboard_check(vk_right) = false and place_free(x,y+1) = false
{
if abs(hspeed) < 2 {hspeed = 0}
else if hspeed < 0 {hspeed += accel_speed*1.25;}
else if hspeed > 0 {hspeed -= accel_speed*1.25;}
}
//Vertical Movement
if keyboard_check_released(vk_up) = true and place_free(x,y+1) = true
{
gravity_direction = 270;
gravity = 1;
}
else if keyboard_check(vk_up) = true and place_free(x,y+1) = false
{
vspeed -= 12;
}
else if place_free(x,y+1) = true and vspeed <= 0
{
gravity = .75;
}
scr_plr_solid_collision:
if place_free(x+hspeed,y+vspeed) = false
{
hspeed = 0;
vspeed = 0;
}
if place_free(x,y+1) = false
{
gravity = 0;
}
if place_free(x+hspeed,y) = false
{
if hspeed > 0 {move_contact_solid(0,0);}
else if hspeed < 0 {move_contact_solid(180,0);}
hspeed = 0;
}
}
Here is a possibility.
I am assuming that you are running scr_plr_movement first, and scr_plr_solid_collision after it.In scr_plr_movement, you have:Yes, I run scr_plr_movement() before scr_plr_collision(). Those were the two lines I've been looking at, too. I know I have an effective collision system at home, but I was hoping to get this out of the way before I get home.
Reversing the order (calling scr_plr_collision first) allows me to jump, but fails at collision detection. I can force my way into blocks, and if I jump, I get stuck about 12 pixels into the floor before landing.I turned scr_plr_solid_collision with this and it worked well:
Very nice, _Player_! That works just as I wanted it to. I'm probably going to replace my scr_solid_collision script with yours, if that's alright. I'll be sure to credit you for that :D
I'll have to tweak it a bit for collisions above the player, but that's minor work