Legacy GM [Solved] Keep horizontal momentum after collision

G

GrandpaBaner

Guest
I'm currently developing a game where you can't change your momentum in the air after you jump. When jumping into a wall right now my player's horizontal speed changes to zero.

I can't figure out how to return the player's speed back to the original speed before the collision once they pass the height of the wall. An example game that has what I'm trying to accomplish is Volgarr the Viking.

In the picture, I'd want the red box to follow the path of the blue line to make it easy to land on top of the wall.

Here is the basic code for the collision that I currently have which changes the speed to zero the whole time.

//Horizontal Collision
if (place_meeting(x+hsp, y, obj_block))
{
while(!place_meeting(x+sign(hsp), y, obj_block))
{
x += sign(hsp);
}
hsp = 0;
}
 

Attachments

Q

Quinnlan Varcoe

Guest
You could make a temp variable a temp variable that is stored when the horizontal speed is set and after there is no longer a collision that speed is restored.

If you provide more code I could try and help a bit more.
 
G

GrandpaBaner

Guest
Thanks for the reply
You could make a temp variable a temp variable that is stored when the horizontal speed is set and after there is no longer a collision that speed is restored.

If you provide more code I could try and help a bit more.
So I don't know how to use temp variables I guess because I tried to no avail. I couldn't figure how to put the temp variable back into the horizontal speed at the end. I did solve the problem a different way.

I basically said that once the player is 1 pixel from the wall then move the player the opposite direction of his horizontal speed. This canceled out his horizontal speed to be zero until he left the wall where it went to normal.

//movement
x += hsp;
y += vsp;
if (vsp < 20) vsp += grav;

//Jumping
if (gamepad_button_check_pressed(0,gp_face1)) && (place_meeting(x, y+1, obj_block))
{
vsp = jumpspeed * gamepad_axis_value(0,gp_axislv);
hsp = jumpspeed * gamepad_axis_value(0,gp_axislh);
}

//Horizontal Collision
if (place_meeting(x+hsp, y, obj_block))
{
while(!place_meeting(x+sign(hsp), y, obj_block))
{
x += sign(hsp);
}
while (place_meeting(x-sign(hsp), y, obj_block))
{
x -= hsp;
}
if (vsp > 0) hsp = 0;
}


 
Top