LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Programming slopes?

Root / Programming Questions / [.]

Gaelstrom_ValenceCreated:
Someone told me how to do it back on the petit computer wiki but I forgot what they said. tAt My game checks for terrain collision by taking the positions of the player's borders, dividing them by 16 (the size of tiles), and checking an array. And I don't know if it'd matter, but the program only checks for downwards collision if the player's velocity will carry them into a different tile than before. (For the sake of drop down platforms. If I don't, the game checks the tile if it's occupying the space the player's feet are in and prepositions them.)

If you mean to say that each tile of terrain has a 'slope' associated with it, can't you use the array you mention to store this slope data? Note that if the top of the terrain is not the top of the tile, then collisions with the terrain may be off by up to 8 pixels (or up to 16 pixels, depending on how you do it).

If you mean to say that each tile of terrain has a 'slope' associated with it, can't you use the array you mention to store this slope data? Note that if the top of the terrain is not the top of the tile, then collisions with the terrain may be off by up to 8 pixels (or up to 16 pixels, depending on how you do it).
All tiles are either background, (no collision), jump through (one way) and solid. Either way they fill the entire tile.

You mean to say that the terrain in your program is sloped at some angle? Such that at different X-axis positions across a single tile, there exists multiple Y-axis positions? Sounds like your classic y=mx+b to me.

You mean to say that the terrain in your program is sloped at some angle? Such that at different X-axis positions across a single tile, there exists multiple Y-axis positions? Sounds like your classic y=mx+b to me.
They're not currently that way. All terrain currently are tiles tat are 16x16 squares.

they fill the entire tile.
If the entire tile is filled, and the top of the tile is horizontal, what are you using slope for?

they fill the entire tile.
If the entire tile is filled, and the top of the tile is horizontal, what are you using slope for?
I don't currently have slopes, but I do want them. Just don't know how to program them.

You could use some tile array data format to store some horizontal or vertical slope data, perhaps the angle of the slope, then use trigonometric functions to find the x and y components of the angle and use a linear function to find the proper y coordinate (or x coordinate, depending whether it is a vertical or horizontal slope) for the corresponding x coordinate. Edit: Actually, it might just be easier to store the initial Y-axis height of the slope then the final height and use a linear function to find the height on the slope at a given X-coordinate. You'd be storing two numbers, though. Unless a slope always starts at zero and is always positive, because then the initial value would be zero.