# My side scroller has a problem finding where the ground is

Here is the drive with all of my code. I am trying to use a linear equation to determine the height of the ground, but for some reason my ball is always too high or too low.

First, it would help if you posted the code as text where exactly you are doing your ground collisions, and second, I’m just guessing if you’re using pre-made equations to check for collisions, it might not be the equations that are wrong, and you might just be handling modes incorrectly.

if (carl.charX > 4000 || carl.charX < -2000) {

y = m*(carl.charX - (2000*block))+(rHeight+save); //Equation for the height of the ground

}
else {y = rHeight;}

Here is how I determine the height of the ground. I have the if statement because the first 3 blocks are flat at 1500 (rHeight). My equation for m is:
m = (((rHeight+save)-(rHeight+newRand))/(-2000));

Save is the height of the first point in the block, newRand is the height of the end. The block is 2000 pixels wide, so I have -2000 underneath.

Basically I’m using y=mx+b where x is the x of the ball.

What is carl? I’m not seeing that class in the code you added to your drive. It would also help if you wrapped the code in </> preformatted text, seen in the editor’s window.

carl is from the class of My_Guy, so it is his x and y I am tracking. and apologies, I’m new to this.

``````if (carl.charX > 4000 || carl.charX < -2000) {

y = m*(carl.charX - (2000*block))+(rHeight+save); //Equation for the height of the ground

}
else {y = rHeight;}

m = (((rHeight+save)-(rHeight+newRand))/(-2000));
``````