Discuss Scratch

Gamerproscratch
Scratcher
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

whenclickedforeverifkeyapressed?thenchangeXby-5iftouchingExample Wall?thenchangeXby5

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)

DragonPlusMaster
Scratcher
100+ posts

Stuck in Walls

Could you share the project?
theashbreather
Scratcher
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
Scratcher
5 posts

Stuck in Walls

DragonPlusMaster wrote:

Could you share the project?

It's currently a WIP
Gamerproscratch
Scratcher
5 posts

Stuck in Walls

theashbreather wrote:

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
Scratcher
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.
Gamerproscratch
Scratcher
5 posts

Stuck in Walls

deck26 wrote:

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

Powered by DjangoBB