• 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!

GML How to check the closer the object to the point, the great it's y-position and vice versa?

E

Edwin

Guest
For example, I have player object and any X position (or special object), and if player get near it, player goes upper, like for pseudo slopes, because my game has no collision objects like in platformers, but just "y-floor" variable that sets the y-position where player stop falling.

0.png
 

chamaeleon

Member
For example, I have player object and any X position (or special object), and if player get near it, player goes upper, like for pseudo slopes, because my game has no collision objects like in platformers, but just "y-floor" variable that sets the y-position where player stop falling.
Since you have given no indication of how you would like to represent your floor, I'm just going to suggest, based on the picture, to stop vertical downward motion when the player's Y is equal or larger than the linear interpolation Y between two anchor points for the player's X position.
 

NightFrost

Member
Loop through your list of anchor coordinate positions. When you find an anchor that has x-value greater than player x, stop. This is your Right Anchor (being to the right of the player). The previous anchor will be your Left Anchor (being to the left of the player).

The t-value (player's relative position between anchors) is (player x - left anchor x) / ( right anchor x - left anchor x) and will be 0...1.

To get player y position: player y = left anchor y - ((left anchor y - right anchor y) * t value).
 
Top