Landing on downward slopes [SOLVED]

R

Ross

Guest
Hey everyone, this is my first post, so I hope it's in the right section. My problem is a bit of an old school one. I've recently tried to add slopes into my Megaman Zero engine. I can dash, walk and land on the slope moving upward and I can also walk down it, but when I jump downward along the slope and land on it, I bounce off. I understand that this is because it won't register that the character object is currently on the slope. The gravity is still set to .25 when it should be 0, Jump (the variable that tests if you're currently in the air) is set to 1 when it should be 0, and the object's vspeed isn't 0 as it should be. I've been trying different methods all day on this problem, but nothing works. Either it will act as if I haven't added any code at all, or it just stays in the position that it collided with the slope at until the object moves up the slope, then it snaps to the ground, plays the step effect and acts as it should. This is driving me absolutely mad, and if anyone has encountered something like this before and found a solution, your help would be greatly appreciated. I can also post the engine here if it would help.

Landing:
if vspeed < 1 && vspeed != 0 Jump = 1
if Land && !place_free(x,y) y -= 1
if Jump && !place_free(x,y+1)
if Land = 0
{
sound_play(snd_step)
Dashing = 0
Land = 1
alarm[0] = 1
}
if Land Jump = 0

And here's the code I'm using to walk regularly:
if keyboard_check_direct(global.Right) && !keyboard_check_direct(global.Left) && !Dashing
{
repeat (Spe)
{
if place_free(x+1,y+1) && gravity = 0{x += 1 y += 1}
else if place_free(x+1,y) x += 1
else if place_free(x+1,y-1) && gravity = 0 {if Slope < 2 {x += 1 y -= 1 Slope += 1} else Slope = 0}
}}
 
Last edited by a moderator:

Roderick

Member
This has nothing to do with your solution, I'm just confused by the first line of code you've got there.

In English, "if vspeed < 1 && vspeed != 0" says "if vspeed is less than 0 or is between 0 and 1, but isn't exactly 0 or 1". Is there a reason for that? From what I can glean of your code "if vspeed < 0" seems to be a better fit.

I'd recommend putting braces {} around the statements linked to your conditionals. I can't tell how much of the code following "if Jump && !place_meeting" is supposed to be triggered by that conditional, and I'm not sure how much Game Maker is using.

I personally always put my conditions in parentheses, and my statements in braces. That way, I know they'll always be parsed correctly.

I also think it's possible that your "if Land" code that pushes the player up might be the culprit. I don't use place_meeting typically, so I'm not super familiar with how it works, so I could be mistaken.
 
Last edited:
C

CROmartin

Guest
if vspeed < 1 && vspeed != 0 Jump = 1
In English, "if vspeed < 1 && vspeed != 0" says "if vspeed is less than 0 or is between 0 and 1, but isn't exactly 0 or 1". Is there a reason for that? From what I can glean of your code "if vspeed < 0" seems to be a better fit.
Roderick as he said
if Land && !place_free(x,y) y -= 1
For what is this
if Jump && !place_free(x,y+1)
if Land = 0
{
sound_play(snd_step)
Dashing = 0
Land = 1
alarm[0] = 1
}
if Land Jump = 0
so you want say that if you jump and dont touch eneything in air then you triger if land = 0 that trigers code in brackets that says land = 1 it makes only sense if variable land decres jump speed to 0 and then gravity pulls it on floor. And bcs that you probably have problem with bouncing probaly. I am sure you have somewhere in code something combined with this code.. for snaping on ground try this code
Code:
 if place_meeting(slope,x,y) && jump = 0
{
x.slope
y.slope
}
if you have more slope object
make var nearest = instance_nearest(x, y, slope)
so it will look like this
Code:
if place_meeting(slope,x,y) && jump = 0
{
x.nearest
y.nearest
}
I hope that this helped.Sry if I misunderstood your code and sry on bad English
 
R

Ross

Guest
This has nothing to do with your solution, I'm just confused by the first line of code you've got there.

In English, "if vspeed < 1 && vspeed != 0" says "if vspeed is less than 0 or is between 0 and 1, but isn't exactly 0 or 1". Is there a reason for that? From what I can glean of your code "if vspeed < 0" seems to be a better fit.

I'd recommend putting braces {} around the statements linked to your conditionals. I can't tell how much of the code following "if Jump && !place_meeting" is supposed to be triggered by that conditional, and I'm not sure how much Game Maker is using.
I replaced the code with what you suggested here and it worked, thank you. I was always under the impression that "!=" stood for "does not equal", not that it would have made that code any better to begin with.
Landing:
if vspeed < 1 && vspeed != 0 {Jump = 1}
if Land && !place_free(x,y) { y -= 1 }
if Jump && !place_free(x,y+1)
{
if Land = 0
{
sound_play(snd_step)
Dashing = 0
alarm[0] = 1
Land = 1
}
}
Hope that helps. the last "if Jump && !place_free(x,y+1)" is the game asking if you're in the air and you can't fall any further. Also, I should have mentioned this earlier, but all that alarm[0] does is reset the Land variable back to 0 so that it doesn't repeatedly make that stepping noise on an indefinite loop. I thought I'd also add my gravity code:
if place_free(x,y+1) gravity = .25 else {gravity = 0; vspeed = 0;}
I don't think the game is reading that there's a solid under my character. When I hit the slope, the gravity stays at .25 but the vspeed reverts back to 0.
For what is this
"if Land && !place_free(x,y) y -= 1" This code checks to see if you're stuck in the ground when you land and it pushes you above it if you are.
The problem with using the code that you sent revolves around "Jump = 0". Jump won't reset back to 0 when landing on a slope moving downward, it'll bounce off of the slope without resetting Jump or the gravity.
I think the main problem is that it's just not detecting the ground under my character. if it did, Land would = 1, Jump would = 0 and gravity would = 0. There's obviously some kind of collision though, since the vspeed resets upon hitting the slope. Thanks so much for even responding to this topic.
 

Roderick

Member
I was always under the impression that "!=" stood for "does not equal"
That's correct, but unless you're working with an integer, there are thousands of numbers between 0 and 1. So, by checking for "vspeed < 1 && vspeed != 0", you're saying that all those decimal values in between are valid options, when it didn't really look like that was what you were intending.
 
C

CROmartin

Guest
the last "if Jump && !place_free(x,y+1)" is the game asking if you're in the air and you can't fall any further.
I dont get this part... if you jump shouldnt you fall on floor?
if place_free(x,y+1) gravity = .25 else {gravity = 0; vspeed = 0;}
Is this code that detects floor? To me it seems like its. However in code where you detecting floor put on y+vspeed like this {if place_free(x,y+vspeed+1) "bablabla".So myb it will be beter detection.There is no problem responding on your problem.
 
R

Ross

Guest
That's correct, but unless you're working with an integer, there are thousands of numbers between 0 and 1. So, by checking for "vspeed < 1 && vspeed != 0", you're saying that all those decimal values in between are valid options, when it didn't really look like that was what you were intending.
Ah, I see what you mean. Yeah, I'm not quite sure why I coded it like that.
I dont get this part... if you jump shouldnt you fall on floor?
Yes, that's what the code is doing. Jump could be considered the "in air" state. If you're not on the ground, jump is active. When you are in the air and you can't fall any further without colliding, it activates the landing code which makes the footstep noise and sets Jump to 0 since you're no longer in the air.
y+vspeed like this {if place_free(x,y+vspeed+1)
I tried implementing that into my gravity code, but it just makes the object stop before hitting the ground for a few moments, this even happens on normal terrain.
http://www.megafileupload.com/omLA/MMZ_problem.exe
Here's my unedited engine so far. You can use the WASD keys to move, L to jump and O to dash. Try jumping down the slope and keep the A key held and you'll see what I mean.
 
C

CROmartin

Guest
I tried implementing that into my gravity code, but it just makes the object stop before hitting the ground for a few moments, this even happens on normal terrain.
http://www.megafileupload.com/omLA/MMZ_problem.exe
Here's my unedited engine so far. You can use the WASD keys to move, L to jump and O to dash. Try jumping down the slope and keep the A key held and you'll see what I mean.
I played it and to me seems with out weird bugs. It works perfectly(there is no boucing and stfu like that), but I realised what is your slope and its rly hard to make cube land on slope perfectly with out use of physic. You can made code like this if place meeting(x,y,slope)(or what eve code you use to indicate are you on slope) {image_angle = 45} else = 0 . Let me know if you know problems with that
 
R

Ross

Guest
I found out a way to do it after several days of tinkering. I edited the walk script so that it would check if the vspeed = 0 and then activate the walking down slopes code. There's still a problem with jumping up the slopes while dashing, but I feel like I can figure it out. Thanks for all of your help.
 
Top