Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Stuck in Walls
- Gamerproscratch
-
5 posts
Stuck in Walls
So I've been making a Project where it is a 2D top down game with a scrolling map, but with the script I am using for walls of the buildings it results with my character getting stuck in the walls
The script in question
There is a copy for all 4 keys, and the physical X is set to the Variable X
I have no idea what causes it, and it would be appreciated if someone could help
The script in question
There is a copy for all 4 keys, and the physical X is set to the Variable X
I have no idea what causes it, and it would be appreciated if someone could help
Last edited by Gamerproscratch (Dec. 23, 2024 22:30:06)
- theashbreather
-
88 posts
Stuck in Walls
You could try changing X by 6 instead of 5 because it gets stuck in a infinite loop due to how your code works.
- Gamerproscratch
-
5 posts
Stuck in Walls
You could try changing X by 6 instead of 5 because it gets stuck in a infinite loop due to how your code works.
It creates an easy way to go through hitboxes, wedging yourself in then pressing the reverse key
- deck26
-
1000+ posts
Stuck in Walls
Why use a separate variable for X? You want the sprite to move when you cahnge X so you can tell when you need to undo the move. Changing a separate variable means you break the connection with the actual movement.
So for example, you change X by a value that will result in touching the wall. You then move the sprite. You then change X again if the key is still down, check for touching and undo that new move but the first move that meant you were touching the wall hasn't been undone.
So for example, you change X by a value that will result in touching the wall. You then move the sprite. You then change X again if the key is still down, check for touching and undo that new move but the first move that meant you were touching the wall hasn't been undone.
- Gamerproscratch
-
5 posts
Stuck in Walls
Why use a separate variable for X? You want the sprite to move when you cahnge X so you can tell when you need to undo the move. Changing a separate variable means you break the connection with the actual movement.
So for example, you change X by a value that will result in touching the wall. You then move the sprite. You then change X again if the key is still down, check for touching and undo that new move but the first move that meant you were touching the wall hasn't been undone.
The way my game works is by using a collection of large sprites to create a map, so a variable makes it easy to control all of the sprites at once
- Discussion Forums
- » Help with Scripts
-
» Stuck in Walls