Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » World Detection Variable
- MalSalp
-
Scratcher
100+ posts
World Detection Variable
Project: https://scratch.mit.edu/projects/1367496636/
There is a variable called 'Touching Ground?' (not to be confused with 'touching') and what I want to do with this variable is check if the 'Player Hitbox' sprite is touching the 'World Hitbox' sprite by saying 'true' or 'false', however I'm confused because it always says 'false' when I put this code in somewhere in the code of the 'Player Hitbox' sprite:
(Also I don't want the variable to detect just the ground so ignore the name)
By the way, the project is for this collab called Velocity Drive which is hosted by @TailsANDAggressiveOM, and if you want to help make this collab, go into this project: https://scratch.mit.edu/projects/1352759473/
There is a variable called 'Touching Ground?' (not to be confused with 'touching') and what I want to do with this variable is check if the 'Player Hitbox' sprite is touching the 'World Hitbox' sprite by saying 'true' or 'false', however I'm confused because it always says 'false' when I put this code in somewhere in the code of the 'Player Hitbox' sprite:
set [ Touching Ground? v] to <touching [World Hitbox v] ?>Is there a solution?
(Also I don't want the variable to detect just the ground so ignore the name)
By the way, the project is for this collab called Velocity Drive which is hosted by @TailsANDAggressiveOM, and if you want to help make this collab, go into this project: https://scratch.mit.edu/projects/1352759473/
Last edited by MalSalp (Aug. 9, 2026 17:40:32)
- ThePaperMakers
-
Scratcher
100+ posts
World Detection Variable
The problem is that your collision code fixes the overlap before the variable can update. To change that you can put the variable update right before you do collisions.
If you solely want to know if you’re touching the ground and not if you’re touching the walls you can do this:
In your
custom block right after
add the variable update
If you solely want to know if you’re touching the ground and not if you’re touching the walls you can do this:
In your
define Move - in steps (Steps)
custom block right after
change y by ((speed y)/(Steps::custom))
add the variable update
set [touching ground? v] to <touching (World Hitbox v) ?>
- MalSalp
-
Scratcher
100+ posts
World Detection Variable
The problem is that your collision code fixes the overlap before the variable can update. To change that you can put the variable update right before you do collisions.Still says false even when I'm touching the ground
If you solely want to know if you’re touching the ground and not if you’re touching the walls you can do this:
In yourdefine Move - in steps (Steps)
custom block right afterchange y by ((speed y)/(Steps::custom))
add the variable updateset [touching ground? v] to <touching (World Hitbox v) ?>
Also meant went the player touches the ground or wall lol
- ThePaperMakers
-
Scratcher
100+ posts
World Detection Variable
I forgot to mention that you also have to delete the idk custom block that you placed to test the variable.
Could you please save the changes in your project so I can look if you placed everything correctly?
Could you please save the changes in your project so I can look if you placed everything correctly?

- MalSalp
-
Scratcher
100+ posts
World Detection Variable
I forgot to mention that you also have to delete the idk custom block that you placed to test the variable.oh yeah it works now but how about the wall detection as well?
Could you please save the changes in your project so I can look if you placed everything correctly?
- ThePaperMakers
-
Scratcher
100+ posts
World Detection Variable
Bruh, I just realised I overlooked the logical and simple method. There is already the touching variable.
. Delete the touching ground? variable update thing I told you to add. Set is touching ground? to false at the beginning of the move in steps custom block.
In the two if conditions (if touching > 0) add a set touching ground? to true. That is it.
. Delete the touching ground? variable update thing I told you to add. Set is touching ground? to false at the beginning of the move in steps custom block.In the two if conditions (if touching > 0) add a set touching ground? to true. That is it.
Last edited by ThePaperMakers (Aug. 9, 2026 18:06:28)
- ThePaperMakers
-
Scratcher
100+ posts
World Detection Variable
Sorry if I explained it badly. Here it is in blocks:
define Move - in steps (Steps)
set [touching ground? v] to [false]
change [falling v] by (1)
repeat (Steps)
set [last value v] to (x position)
change x by ((speed x)/(Steps))
Check Touching Solid ::custom
if <(touching) > (0)> then
Collide X: Slope or Wall? ::custom
set [touching ground? v] to [true]
end
set [last value v] to (y position)
change y by ((speed y)/(Steps))
Check Touching Solid ::custom
if <(touching) > (0)> then
Collide Y: Ceiling or Floor? ::custom
set [touching ground? v] to [true]
end
end
- MalSalp
-
Scratcher
100+ posts
World Detection Variable
Sorry if I explained it badly. Here it is in blocks:what about touching the walls (again)define Move - in steps (Steps)
set [touching ground? v] to [false]
change [falling v] by (1)
repeat (Steps)
set [last value v] to (x position)
change x by ((speed x)/(Steps))
Check Touching Solid ::custom
if <(touching) > (0)> then
Collide X: Slope or Wall? ::custom
set [touching ground? v] to [true]
end
set [last value v] to (y position)
change y by ((speed y)/(Steps))
Check Touching Solid ::custom
if <(touching) > (0)> then
Collide Y: Ceiling or Floor? ::custom
set [touching ground? v] to [true]
end
end
Last edited by MalSalp (Aug. 9, 2026 18:51:00)
- ThePaperMakers
-
Scratcher
100+ posts
World Detection Variable
Oh, the touching ground variable detects touching wall and ground.
If you want them seperate you will have to make a new variable named touching wall?.
It would look like this:
If you want them seperate you will have to make a new variable named touching wall?.
It would look like this:
define Move - in steps (Steps)
set [touching ground? v] to [false]
set [touching wall? v] to [false]
change [falling v] by (1)
repeat (Steps)
set [last value v] to (x position)
change x by ((speed x)/(Steps))
Check Touching Solid ::custom
if <(touching) > (0)> then
Collide X: Slope or Wall? ::custom
set [touching wall? v] to [true]
end
set [last value v] to (y position)
change y by ((speed y)/(Steps))
Check Touching Solid ::custom
if <(touching) > (0)> then
Collide Y: Ceiling or Floor? ::custom
set [touching ground? v] to [true]
end
end
- MalSalp
-
Scratcher
100+ posts
World Detection Variable
Oh, the touching ground variable detects touching wall and ground.It works!!
If you want them seperate you will have to make a new variable named touching wall?.
It would look like this:define Move - in steps (Steps)
set [touching ground? v] to [false]
set [touching wall? v] to [false]
change [falling v] by (1)
repeat (Steps)
set [last value v] to (x position)
change x by ((speed x)/(Steps))
Check Touching Solid ::custom
if <(touching) > (0)> then
Collide X: Slope or Wall? ::custom
set [touching wall? v] to [true]
end
set [last value v] to (y position)
change y by ((speed y)/(Steps))
Check Touching Solid ::custom
if <(touching) > (0)> then
Collide Y: Ceiling or Floor? ::custom
set [touching ground? v] to [true]
end
end
I'll probably unshare the project until I'm finished (or if there is another bug that I don't know how to fix)
- Discussion Forums
- » Help with Scripts
-
» World Detection Variable