LunarTaqq
Member
Hey! This is my first post here and I'm kind of a beginner so I might not know exactly what I'm doing.
I'm attempting to make a platform game, and I am trying to be able to have my character run up slopes. The only kind of slope I want in the game is a 45 degree one, so I know I don't need to do anything too super fancy. I've looked up a couple tutorials and they are all very complicated. Any tips?
Current collision and movement code:
//Player Input
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space) || keyboard_check_pressed(ord("W"));
//Hori Movement
var move = key_right - key_left;
hsp = move * walksp;
//Vert Movement
vsp += grv;
if (place_meeting(x, y + 1, obj_wall)) && (key_jump)
{
vsp = -4.5;
}
//Hori Collision
if (place_meeting(x + hsp, y, obj_wall))
{
while (!place_meeting(x + sign(hsp), y, obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vert Collision
if (place_meeting(x, y + vsp, obj_wall))
{
while (!place_meeting(x, y + sign(vsp), obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
Anything will help. Thanks!
-LunarTaqq
I'm attempting to make a platform game, and I am trying to be able to have my character run up slopes. The only kind of slope I want in the game is a 45 degree one, so I know I don't need to do anything too super fancy. I've looked up a couple tutorials and they are all very complicated. Any tips?
Current collision and movement code:
//Player Input
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space) || keyboard_check_pressed(ord("W"));
//Hori Movement
var move = key_right - key_left;
hsp = move * walksp;
//Vert Movement
vsp += grv;
if (place_meeting(x, y + 1, obj_wall)) && (key_jump)
{
vsp = -4.5;
}
//Hori Collision
if (place_meeting(x + hsp, y, obj_wall))
{
while (!place_meeting(x + sign(hsp), y, obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vert Collision
if (place_meeting(x, y + vsp, obj_wall))
{
while (!place_meeting(x, y + sign(vsp), obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
Anything will help. Thanks!
-LunarTaqq
Attachments
-
55.6 KB Views: 10