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

**URL:** https://discourse.processing.org/t/my-side-scroller-has-a-problem-finding-where-the-ground-is/33444
**Category:** Coding Questions
**Created:** [November 10, 2021, 5:31pm UTC](https://discourse.processing.org/t/my-side-scroller-has-a-problem-finding-where-the-ground-is/33444 "2021-11-10T17:31:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DividedRabbit](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@DividedRabbit](https://discourse.processing.org/u/DividedRabbit)
#### Post date: [November 10, 2021, 5:31pm UTC](https://discourse.processing.org/t/my-side-scroller-has-a-problem-finding-where-the-ground-is/33444/1 "2021-11-10T17:31:16Z")

</div>

[https://drive.google.com/drive/folders/1qZGnHtEltQCCeqCsDzOSHIyZKUQMSOJt?usp=sharing](https://drive.google.com/drive/folders/1qZGnHtEltQCCeqCsDzOSHIyZKUQMSOJt?usp=sharing)

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.

---

<div class="post-metadata">

### Author: ![UnusualUsual](https://avatars.discourse-cdn.com/v4/letter/u/e274bd/32.png) [@UnusualUsual](https://discourse.processing.org/u/UnusualUsual)
#### Post date: [November 10, 2021, 5:36pm UTC](https://discourse.processing.org/t/my-side-scroller-has-a-problem-finding-where-the-ground-is/33444/2 "2021-11-10T17:36:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DividedRabbit](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@DividedRabbit](https://discourse.processing.org/u/DividedRabbit)
#### Post date: [November 10, 2021, 7:18pm UTC](https://discourse.processing.org/t/my-side-scroller-has-a-problem-finding-where-the-ground-is/33444/3 "2021-11-10T19:18:46Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![UnusualUsual](https://avatars.discourse-cdn.com/v4/letter/u/e274bd/32.png) [@UnusualUsual](https://discourse.processing.org/u/UnusualUsual)
#### Post date: [November 11, 2021, 3:09am UTC](https://discourse.processing.org/t/my-side-scroller-has-a-problem-finding-where-the-ground-is/33444/4 "2021-11-11T03:09:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DividedRabbit](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@DividedRabbit](https://discourse.processing.org/u/DividedRabbit)
#### Post date: [November 11, 2021, 6:41am UTC](https://discourse.processing.org/t/my-side-scroller-has-a-problem-finding-where-the-ground-is/33444/5 "2021-11-11T06:41:16Z")

</div>

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.

```auto
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));

```
