# Can sprites move up down by itself

**URL:** <https://forum.code.org/t/can-sprites-move-up-down-by-itself/31910>\
**Category:** Coding and Debugging Help\
**Created:** [December 12, 2019, 5:43pm UTC](https://forum.code.org/t/can-sprites-move-up-down-by-itself/31910 "2019-12-12T17:43:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thompam1](https://avatars.discourse-cdn.com/v4/letter/t/f4b2a3/32.png) [@thompam1](https://forum.code.org/u/thompam1)\
**Post date:** [December 12, 2019, 5:43pm UTC](https://forum.code.org/t/can-sprites-move-up-down-by-itself/31910/1 "2019-12-12T17:43:47Z")

</div>

One of my students is trying to make one of their sprites go up down repeatedly on its own. He was able to do it with his second sprite going side to side. Is it possible for the sprite to go up and down? Here is his what he has so far…

> **[Check out what I made](https://studio.code.org/projects/gamelab/1K-Lts8s6syfN5hmZTH4DFhRRZmgAMRmcx0j4u51qjo)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [December 12, 2019, 6:15pm UTC](https://forum.code.org/t/can-sprites-move-up-down-by-itself/31910/2 "2019-12-12T18:15:50Z")

</div>

Looks like he was on the right path, but the line of code where he checks to see if it is == to 120 could be the problem. Due to how code runs, it is always safer to check if it’s \>= to 120 rather than specifically equal to 120, because it is possible that it checks the condition at 119 and then doesn’t check again until tiger.y is at 123 and then, it misses the code to turn around.

I changed that in his code and then it was working, but I also had to change a line of code in his tigerRun function (line 64, I believe) to check when it reaches the top. Those are obviously adjustable, but here’s my remix version if you want to have a look at it.

[Tiger Maze Remix](https://studio.code.org/projects/gamelab/_adkT24gdYOUpD7cTIwFfXfigrDWYy4xk-xsrd6Pnwo)

Best of luck,

Mike

---

<div class="post-metadata">

**Author:** ![infinitestasis](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/infinitestasis/32/5047_2.png) [@infinitestasis](https://forum.code.org/u/infinitestasis)\
**Post date:** [December 13, 2019, 11:08pm UTC](https://forum.code.org/t/can-sprites-move-up-down-by-itself/31910/3 "2019-12-13T23:08:40Z")

</div>

This is one of the key problems with the code. It checks whether tiger.y is exactly 120 but doesn’t account for when tiger.y passes 120.  
 ![Screen Shot 2019-12-13 at 2.56.57 PM](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/7/7893fdc53e7b60a8ab04e73a0d08ad169eec0f51.png)  
You can see here that tiger.y never actually hits 120 and skips from 119 to 123.  
 ![Screen Shot 2019-12-13 at 2.59.38 PM](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/4/43ad3f35bbefb739bb3a38e68d614eb8a9729eb5.png)  
`tiger.y >= 30` is also wrong and it should be `tiger.y <= 30`  
`tiger.y == 120` should be changed to the opposite (greater than or equal to): `tiger.y >= 120`  
After these edits, you may find that the tiger is not actually moving, that’s because tiger.y is 31. Simply go to line 8, where it says: `var tiger = createSprite(46, 31)` and change 31 to 30.  
[Here are the changes](https://studio.code.org/projects/gamelab/5LeJfeIS-B1U1hi-T6Hl7BqxKeJ0v72hagzx6bQTT0E)
