hi im making a game and my charcter keeps going out of the screen how do fix this
hate when that happens, I usually add walls surronding the outside boundaries, and the hitTest command would do the rest of the work.
Here’s the code for the wall on the right:
if(this.hitTest(PLAYER){
player.x-=TYPE A NUMBER IN HERE
}
Here’s the code for the wall on the left:
if(this.hitTest(PLAYER){
player.x+=TYPE A NUMBER IN HERE
}
Swap the word, “PLAYER,” with the name of your character, and phrase, “TYPE A NUMBER IN HERE” with the same number as the speed of your character, or more
Hope it works!
btw- write the code in the “update” script, not the one named “default”
i tried to do that it doesnt seem to work
assuming the player is a square, make sure the square is a clip and name it to a reasonable name, like “player”. TYPE A NUMBER IN HERE, I’m sure you figured out, means to put in whatever number fits well for the player’s speed.
It sorta works but when I move diagonally, It still goes past the walls.
If that happens, just either make the numbers plugged in higher than the players speed, or try to use a different type of wall from here: making walls and stuff tutorial.wick (335.0 KB)
Let me know if it helps