if (player.y + 6.345 > ground) { /**/ }
if (IsPersonObstructed(name, player.x, player.y+6.345)) { player.y = ground_line;}
if (IsPersonObstructed(name, player.x, player.y+6.345)) { // we overshot the ground somewhere, backtrack until we are on top: for (var i = 1; i <= 6; i++) { // 6 from Math.floor(6.345) var y = player.y + (6 - i); // 6 from Math.floor(6.345) if (!IsPersonObstructed(name, player.x, y)) player.y = y; }}
When a character hits the ground is one of the trickiest parts of gravity.Can you describe the process you use to check for obstructions? I'll have a look at the code, but (in my experience) it's hard to figure out these kinds problems without a lot of careful reasoning and even more trial and error.
You calculate fall speed going down and check a 'ground line'. Say it's in pixels. If you are falling down at 6.345 pixels (fairly fast), check if it crosses the ground line. So,
Code: (js) [Select]if (IsPersonObstructed(name, player.x, player.y+6.345)) { player.y = ground_line;}Try it out with a constant value first (all tiles on platform are the same height).
Ah, so should I create a function then to, given X, find the Y position of the ground, as opposed to relying on Sphere's obstruction checking?