# GMS 2 Sonic-Like 360° Slope Movements?

Discussion in 'Programming' started by CheatingPenguin, Jul 20, 2019.

Tags:
1. ### CheatingPenguinMember

Joined:
Jul 11, 2019
Posts:
4
Hello!

I'm trying to get my player object to be able to walk up and around slopes similar to how Sonic is able to run through loops.
My player can currently walk left and right.

I've tried implementing 360° Slope Movements onto my player object for the past 4 days straight but to no avail. I'm aware that sin and cos are necessary, but I'm not sure how to use them, or why exactly I have to use them. I also know I need to calculate the angle of the floor relative to my player's rotation, but again I believe that requires sin and cos (which I'm not sure exactly how to apply).

I've tried the following:
The YouTube tutorial was great, but I messed up the code somewhere and it's hard for me to know the fix if I don't understand how everything is working to make the slopes possible.

If anybody has any ideas (even if it's not an entire solution) please share it. I'm really at a loss here and as far as I know, this is the hardest obstacle my game is facing.

Thanks

2d_warrior likes this.
2. ### chamaeleonMember

Joined:
Jun 21, 2016
Posts:
931
You need sin() and cos() because you are working with a point location and a direction, and you place things in an x/y coordinate system. So in the general case, given some current position, sin() helps you find out the amount you move up or down in y when you you attempt to move in a certain direction/angle, while cos() gives you the amount you move left or right in x. lengthdir_x() and lengthdir_y() hides a tiny bit of calculation from you (but not a whole lot...) and gives you the necessary x and y offset you need to apply to the current position of your instance given a distance to travel and which direction to travel, but they do nothing different than the raw math you'd use using cos() (used behind the scenes in lengthdir_x()) and sin() (used behind the scenes in lengthdir_y()).

Because all the math is based on straight lines (a starting point and a direction/angle), I would imagine that some of the work the engine has to do is to possibly fudge the movement or the next angle/direction after it has been calculated to ensure the player stays on the ground and doesn't fly off due to accumulating differences between calculations and a perfect zero-error movement path (which is generally unattainable given inherent limitations in computer math computations).

Last edited: Jul 20, 2019
2d_warrior likes this.

Joined:
Oct 19, 2016
Posts:
821
4. ### CheatingPenguinMember

Joined:
Jul 11, 2019
Posts:
4
I believe I understand it a bit more now.

If I'm understanding you correctly, cos will tell me how much to move the player left or right, on top of their horizontal movement.
So if my player is moving to the right and goes up a slope, cos will be a negative value that's added to their horizontal movement.
And sin is basically the same thing but for the y-axis.

If that's correct, then my next step is finding the angle. I'm thinking of having a script that has 2 lines scanning the ground under the player to find out the angle of the slope using the point_direction function. Though I'm not quite sure as I believe I need to make the 2 sensor lines rotate around with the player.

I'm not exactly sure how to put it all together though

5. ### CheatingPenguinMember

Joined:
Jul 11, 2019
Posts:
4
I don't know how useful it would be to me though as reading through other's engines to understand what is going on is difficult for me (even with comments). Though thanks for the suggestion