A
AtomicToilet
Guest
Hola!
I'm having a crack at an endless runner variation, where instead of objects coming towards the player, the player is constantly moving forward. I've tried modifying an existing movement script so that this happens, and it works, but every time I change into the attack state on a slope (going up) the player object 'sinks' into the slope.
I think/suspect it may have something to do with using speed as a variable for checks as opposed to x [ie. in the Player Create Event, I put speed = 1 and spd = 1, the idea being that spd is the variable that will increase, with speed remaining constant as a control ie. movement = speed x spd. I don't know if this is unnecessary or not, but it seems to make sense to me!].
The thing is, because I'm not using any buttons to move forward, I'm not sure how to tweak the movement code so that it uses x += 1 instead (for example). [This is for a one button game jam - (W) attacks with a quick press, or jumps when held for a moment then released, which both work fine, too]
Alternatively, maybe it's how I've set up the attack change state? Maybe this needs an extra condition? The sprite mask is the same as the player and I have no issues changing states/with collisions on a flat/horizontal surface.
Here's the code! Gracias for any suggestions!
------------------------------
[The on_ground variable is used for animation states, which I've left out here because there's no issue with those]
I'm having a crack at an endless runner variation, where instead of objects coming towards the player, the player is constantly moving forward. I've tried modifying an existing movement script so that this happens, and it works, but every time I change into the attack state on a slope (going up) the player object 'sinks' into the slope.
I think/suspect it may have something to do with using speed as a variable for checks as opposed to x [ie. in the Player Create Event, I put speed = 1 and spd = 1, the idea being that spd is the variable that will increase, with speed remaining constant as a control ie. movement = speed x spd. I don't know if this is unnecessary or not, but it seems to make sense to me!].
The thing is, because I'm not using any buttons to move forward, I'm not sure how to tweak the movement code so that it uses x += 1 instead (for example). [This is for a one button game jam - (W) attacks with a quick press, or jumps when held for a moment then released, which both work fine, too]
Alternatively, maybe it's how I've set up the attack change state? Maybe this needs an extra condition? The sprite mask is the same as the player and I have no issues changing states/with collisions on a flat/horizontal surface.
Here's the code! Gracias for any suggestions!
------------------------------
Code:
//React to inputs
move = speed;
hsp = move * spd;
if (vsp < 10) vsp += grav;
if (place_meeting(x,y+1,obj_wall))
{
on_ground = false;
vsp = key_up * -jumpspeed
}
else if (!place_meeting(x,y+2,obj_wall))
{
on_ground = true;
}
//Horizontal Collision - the number in <= abs (4*hspd) affects how steep a slope the player can go up
// lower numbers = very slight slopes, higher numbers = very steep, with 1 being typical.
//Horizontal Collision
if place_meeting(x+hsp,y,obj_wall)
{
yplus = 0;
while (place_meeting(x+hsp,y-yplus,obj_wall) && yplus <=abs (1*hsp)) yplus += 1;
if place_meeting(x+hsp,y-yplus,obj_wall)
{
while (!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
else
{
y -= yplus
}
}
x += hsp;
//Down slopes
if !place_meeting(x,y,obj_wall) && vsp >= 0 && place_meeting(x,y+2+abs(hsp),obj_wall)
{while(!place_meeting(x,y+1,obj_wall)) {y += 1;}}
//Vertical 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;
// check if on the ground or not after collision
on_ground = place_meeting(x, y+1, obj_wall);
//Change states
if (keyboard_check_pressed(ord("W")))
{
state = "Attack";
image_index = 0;
}