• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Physics Slopes

S

Samus

Guest
An experiment I started using the GMS Physics Engine a while ago has become a kind of large project. I've hit a minor road-bump though, which would be slopes. The character goes up the slopes just fine, because when I apply the force to move I have a y force of -20. But when he stops moving he starts to slide back down again unless the slope is really small. I'm looking for a way to make it not slide down on slopes that are smaller than 45 degrees. I've tried many different methods, but none of them get quite the effect I'm looking for. I was wondering if anyone here had a preferred method? Your ideas would be very helpful, Thanks!
 
S

Samus

Guest
Get the sprite width and sprite height of the collision object.
Thank's for replying, Misty. How would that help me to stop it from sliding downhill?

That's how it works in the real world. Raise the friction.
Yes, I know that's how it works in the real world, but in my case I sometimes need some physics that aren't physically possible, but make a good effect. My game is a multiplayer game with many characters to choose from, one of which is a lot more "slippery" than the others because I gave him less friction. Increasing the friction does kind of hurt that effect, so I was looking for a work-around. But this will work for the other ones. :)
 
P

Pyxus

Guest
Thank's for replying, Misty. How would that help me to stop it from sliding downhill?


Yes, I know that's how it works in the real world, but in my case I sometimes need some physics that aren't physically possible, but make a good effect. My game is a multiplayer game with many characters to choose from, one of which is a lot more "slippery" than the others because I gave him less friction. Increasing the friction does kind of hurt that effect, so I was looking for a work-around. But this will work for the other ones. :)
Well remember, the physics system is meant to emulate realistic physics so if you really need to work around this "slope" issue you have to tackle it with that in mind. The reason the character starts falling down the slope is because of gravity which is a force, if you want the character to not fall down the slope then you need a force that opposes gravity. That force doesn't necessarily need to be the force of friction defined in game maker (i.e you can apply your own force when the desired conditions are met) but it has to be an applied force, if you move the instance's x and y manually to stop them sliding downhill you'll break the physics simulation. You could also try turning down your gravity so that a weaker friction force will be enough to oppose the sliding.

In summary, bump up your friciton like @TheouAegis said, apply your own friction-like force when your desired conditions are met, or turn down your gravity.
 
Last edited by a moderator:
M

Misty

Guest
That's how it works in the real world. Raise the friction.
Nope. In real life hills are not made of steel or glass. They are made of bumpy soft surfaces. And we have feet which rotate and dig into the surface.

In game maker you are essentially a ball or block, on a perfectly flat steel or glass surface. Raising the friction will simply prevent forward movement.

Thank's for replying, Misty. How would that help me to stop it from sliding downhill?
You stop it from sliding downhill. When the collision event is detected you get the sprite width and sprite height from the colliding instance to determine the slope.
And if the slope is beyond a certain value you disable the gravity.

So I recommend making a custom gravity rather than a global gravity since gravity cannot be turned off per-instance.
 

TheouAegis

Member
You're saying you cannot stand on the sloped piece of steel? Yeah, millions of schoolkids would disagree with you there.
 
S

Samus

Guest
Nope. In real life hills are not made of steel or glass. They are made of bumpy soft surfaces. And we have feet which rotate and dig into the surface.

In game maker you are essentially a ball or block, on a perfectly flat steel or glass surface. Raising the friction will simply prevent forward movement.


You stop it from sliding downhill. When the collision event is detected you get the sprite width and sprite height from the colliding instance to determine the slope.
And if the slope is beyond a certain value you disable the gravity.

So I recommend making a custom gravity rather than a global gravity since gravity cannot be turned off per-instance.
Ah, I understand now. Yes, I did that in order to determine the slope's theta, but I didn't disable gravity, I applied a force (phy_mass * -50, 50 is my gravity) to offset gravity. This resulted in the object bouncing downhill instead of sliding. I think I will go with what Pyxus said and try goofing off with the gravity a bit. I'll also have to increase the density though so it falls at the right speed, which might mess with its friction as well. Though if I just made it so one player was lighter than the other instead of just having less friction, it would jump higher, stay in the air longer and skid easier, which is everything I went through all the hard work of coding it to do anyway! That should work goodly, I'll try it!
 
M

Misty

Guest
You're saying you cannot stand on the sloped piece of steel? Yeah, millions of schoolkids would disagree with you there.
Because it's riveted steel. You can't walk up a metal slide without falling down it, unless you grab on to the edges of the slide or run up it really fast.

The equivalent of what he's asking game maker to do is put a ball or axis-aligned block onto a metal slide and expecting it not to slide down. So he has to take certain measures to alter nature.

I suggested to him to put a custom gravity, but he chose another path to just apply a force equal to phy_mass*gravity. This behavoir is unknown to me, may work may not.

As far as it bouncing he needs to disable the restitution. Unless he means skipping which is purely nature since he is applying a horizontal motion to the slope, if he wants to avoid skipping he should put the angle of motion parralel to the slope.
 
S

Samus

Guest
Yeah, I see what your saying with the not being able to stand on riveted steel. A block with no legs to brace itself with and no means by which to resist the pull of gravity would just slide. I had restitution disabled, but for some reason it still bounced. It was like the force was pushing it up, it fell, and got pushed back up again, which didn't make sense to me because the force was calculated for the same as the force of gravity. But what you just said about having to change the direction of the force applied in order to resist gravity makes sense. My opposing force was just going straight up, but gravity isn't pulling straight down in this case, its also pulling horizontally. So if I would need to calculate both the x force and the y force in order to keep it still? If that could do the trick, it would be a lot better, turns out increasing the density won't increase the speed at which the object falls, acceleration due to gravity is always the same regardless of mass. So currently my players hover in the air a little longer than I would like, but its still pretty good.
 
P

Pyxus

Guest
Yeah, I see what your saying with the not being able to stand on riveted steel. A block with no legs to brace itself with and no means by which to resist the pull of gravity would just slide. I had restitution disabled, but for some reason it still bounced. It was like the force was pushing it up, it fell, and got pushed back up again, which didn't make sense to me because the force was calculated for the same as the force of gravity. But what you just said about having to change the direction of the force applied in order to resist gravity makes sense. My opposing force was just going straight up, but gravity isn't pulling straight down in this case, its also pulling horizontally. So if I would need to calculate both the x force and the y force in order to keep it still? If that could do the trick, it would be a lot better, turns out increasing the density won't increase the speed at which the object falls, acceleration due to gravity is always the same regardless of mass. So currently my players hover in the air a little longer than I would like, but its still pretty good.
How familiar are you, if at all, with classical mechanics samus? Its not an absolutely necessity to understand it when using box2d physics but it helps.
 
M

Misty

Guest
Yeah, I see what your saying with the not being able to stand on riveted steel. A block with no legs to brace itself with and no means by which to resist the pull of gravity would just slide. I had restitution disabled, but for some reason it still bounced. It was like the force was pushing it up, it fell, and got pushed back up again, which didn't make sense to me because the force was calculated for the same as the force of gravity. But what you just said about having to change the direction of the force applied in order to resist gravity makes sense. My opposing force was just going straight up, but gravity isn't pulling straight down in this case, its also pulling horizontally. So if I would need to calculate both the x force and the y force in order to keep it still? If that could do the trick, it would be a lot better, turns out increasing the density won't increase the speed at which the object falls, acceleration due to gravity is always the same regardless of mass. So currently my players hover in the air a little longer than I would like, but its still pretty good.
That is why I said, you need to disable the global gravity and put in a custom gravity, which at this point I think you need to do.

Put the global gravity to zero because it may be inducing a torque or the step iterations are misaligned with your force somehow.
Instead you are going to have to induce gravity for each object manually, by increasing their phy_speed_y each step.

Also, I don't understand what of your code is causing players to hover in the air, the physics should be altered only when they are touching the ground.
 
Top