# Help for student Unit 3L18

**URL:** <https://forum.code.org/t/help-for-student-unit-3l18/32025>\
**Category:** Coding and Debugging Help\
**Tags:** csd-unit-3-lesson-18\
**Created:** [January 9, 2020, 4:42pm UTC](https://forum.code.org/t/help-for-student-unit-3l18/32025 "2020-01-09T16:42:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crosado](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@crosado](https://forum.code.org/u/crosado)\
**Post date:** [January 9, 2020, 4:42pm UTC](https://forum.code.org/t/help-for-student-unit-3l18/32025/1 "2020-01-09T16:42:37Z")

</div>

Student would like to have his character not go off screen when the game is played - how would he achieve this?

var character = createSprite(200, 200);  
character.setAnimation(“flyer”);  
var coin = createSprite(randomNumber(0, 400), randomNumber(0, 400));  
coin.setAnimation(“coin”);  
var e = createSprite(200, 200);  
e.setAnimation(“e”);  
e.scale = 0.5;  
e.rotationSpeed = 3;

function draw() {  
background(“skyblue”);

// Simulating Gravity  
character.velocityY = character.velocityY + 0.1;

// update sprites  
//it’s right here  
if(keyWentDown(“up”)){  
character.velocityY = -5;  
}  
if (character.velocityX \>= -5) {  
if (keyDown(“left”)) {  
character.velocityX = character.velocityX + -.5;  
}  
}  
if ((character.velocityX) \<= 5) {  
if (keyDown(“right”)) {  
character.velocityX = character.velocityX + .5;  
}  
}  
if (character.isTouching(coin)) {  
coin.x = randomNumber(0, 400);  
coin.y = randomNumber(0, 400);  
}  
if (coin.isTouching(e)) {  
coin.x = randomNumber(0, 400);  
coin.y = randomNumber(0, 400);  
}

character.bounceOff(e);  
rect(0, 0, 400, 10);  
rect(0, 0, 10, 400);  
rect(0, 400, 400, -10);  
rect(400, 400, -10, -400);  
drawSprites();  
}  
\*\*[https://studio.code.org/s/csd3-2019/stage/18/puzzle/16?section\_id=2284631&user\_id=53149456](https://studio.code.org/s/csd3-2019/stage/18/puzzle/16?section_id=2284631&user_id=53149456)  
**What I expect to happen:** character not go off screen  
**What actually happens:** character disppears off screen

---

<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:** [January 9, 2020, 7:57pm UTC](https://forum.code.org/t/help-for-student-unit-3l18/32025/2 "2020-01-09T19:57:11Z")

</div>

@crosado,

Good to see you again. It’s a bit hard to fully troubleshoot the program without the link to the shared project. Your link unfortunately just takes me to my own program on that level. You could have the student remix and then share the project to get the link, however, I just helped another teacher with almost the exact same issue on almost the same level, so my answer from earlier today may help.

Here’s a link to that answer. Let us know if that helps!

> [@Help with Step 13 or Lesson 17](https://forum.code.org/t/help-with-step-13-or-lesson-17/32001/12):
>
> What is happening is that he can leave the screen (top, bottom, left or right side). There are a number of ways to fix that. In my experience, the easiest is by using two blocks in the sprites toolbox (red/pink blocks). One is called “create edge sprites”. You can put that one at the very top (or near the top) of your code (not inside the draw loop). The other one needs to go in the draw loop somewhere. It is the “sprite.bounceOff” block. change the word sprite to character in your progra…

Mike

---

<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:** [January 9, 2020, 7:57pm UTC](https://forum.code.org/t/help-for-student-unit-3l18/32025/3 "2020-01-09T19:57:53Z")

</div>

If you don’t see the two blocks mentioned in the reply above, you may need to have the student remix the project and that will open all of the sprite blocks.

Mike

---

<div class="post-metadata">

**Author:** ![crosado](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@crosado](https://forum.code.org/u/crosado)\
**Post date:** [January 10, 2020, 2:00pm UTC](https://forum.code.org/t/help-for-student-unit-3l18/32025/4 "2020-01-10T14:00:20Z")

</div>

Thanks a mil, this helped alot 🙂
