Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make a sprite not get stuck on a wall
- Floyd_Fan_Forever
-
Scratcher
18 posts
How to make a sprite not get stuck on a wall
So i have this racing game that i am working on, and i want the player to not be able to go through the wall. here is the code that i have and make any suggestions to change it
when green flag clicked
forever
if <touching [ Outer Wall] ?> then
set x to (OldX)
Set y to(OldY)
end
set [ OldX] to (x position)
set[OldY] to (y position)
end
- knightjj11
-
Scratcher
100+ posts
How to make a sprite not get stuck on a wall
Maybe when your sprite touches the wall make it move a certain amount of steps backward.
Example:
Example:
when green flag clicked
forever
if <touching [Outer wall] ?> then
move (-5) steps
end
end
- Floyd_Fan_Forever
-
Scratcher
18 posts
How to make a sprite not get stuck on a wall
Maybe when your sprite touches the wall make it move a certain amount of steps backward.
Example:when green flag clicked
forever
if <touching [Outer wall] ?> then
move (-5) steps
end
end
But if i made contact with the wall parallel, i would just keep moving back 5 spaces until i'm stuck in it. i want to be able to make contact with the wall and ai cars and not get stuck in them.
- NIKI-KOLCHAGOV
-
Scratcher
500+ posts
How to make a sprite not get stuck on a wall
Ideally you would want to reject any input in the direction of the wall for example when the car is going forward and the player is pressing forward key when you touch the wall you want to make it so that the car cannot move in that direction until the player presses another key
- Discussion Forums
- » Help with Scripts
-
» How to make a sprite not get stuck on a wall