Discuss Scratch

Citrus204
Scratcher
6 posts

How to show distance from the left and right.

I'm trying to make a Toca boca-style game and I'm trying to make sprites hold objects without making sprites for hands. I need for the sprite holding objects to hold objects in two hands and with the current code, it just goes to the right hand.

Current Codefor holding sprite)
when green flag clicked
forever

if <<<touching [ held spritev] ?> and <(distance to [ held sprite v]) > [10]>>> then
broadcast [right v]
else
if <<touching [ held spritev] ?> and <(distance to [ held sprite v]) > [-10]>> then
broadcast [left v]


end
endend

Last edited by Citrus204 (July 14, 2026 22:57:25)

Citrus204
Scratcher
6 posts

How to show distance from the left and right.

I'm not used to the scratch blocks in discussion forums.
ThreeLived
Scratcher
100+ posts

How to show distance from the left and right.

consider sharing your project that way forumers can help better.


“distance to held sprite > -10” <= this just defaults to always true, distance cant be less than 0. Also, for both distance scripts, you probably want to use less than instead of greater than if your using code for adding objects to hands.

also is this code for removing objects from hands? because thats what it seems like.

The main problem i see here is that your checking if this sprite is touching the held sprite. This isnt a problem on its own, but because your using 1 hand (im assuming your sprite here is the hand) to check for two hand positions, it likely is causing an issue with it only being able to check one hand. If anything, you should be using two different positions (one for each hand) to check for each hand and then only anchor the object to that hand if its touching.

Also, you mentioned your trying to make it without sprites for hands. Would this not mean that the objects should check the distance between each hand for every character and then anchor based on which one is closest (if its close enough)?

let me know if i missed something.

Also, it sounds like your new to forums. if someone has not told you previously: below this line is someone's signature, it is not part of the post
10goto10
Scratcher
1000+ posts

How to show distance from the left and right.

I think this would solve the problem of deciding if an object is touching your sprite and is on its left or right.
when this sprite clicked
say []
if <<touching [Hat1 v]?> and <((x position) - ([x position v] of [Hat1 v]::sensing)) \> [0]>> then
say [Hat is on the left and touching this sprite]
end
if <<touching [Hat1 v]?> and <((x position) - ([x position v] of [Hat1 v]::sensing)) \< [0]>> then
say [Hat is on the right and touching this sprite]
end
Citrus204
Scratcher
6 posts

How to show distance from the left and right.

https://scratch.mit.edu/projects/1362204762/

Thanks for all your help, but I need to figure how to keep the phone on each hand.
ThreeLived
Scratcher
100+ posts

How to show distance from the left and right.

you can probably just keep teleporting the object there for as long as it is held,
so if it gets dragged onto the hand, a variable will get set to 1
set [DRAGGING v] to [1]
and when it gets dragged off it gets set to 0
set [DRAGGING v] to [0]
and while dragging is 1, keep making the object teleport there
when green flag clicked
forever
if <(DRAGGING) = [1]> then
go to x: (hand X) y: (hand Y) // for you, it may be better to just keep broadcasting "Quit Left" or "Quit Right" based off which side its on
end
end
by the way, instead of using this block to move left or right:
move () steps
use this one instead:
change x by ()
the reason i say that is because the move () steps block will always depend on the direction of the sprite. Its not a big deal right now, but if you ever want to change the direction of the phone it will become a problem.
10goto10
Scratcher
1000+ posts

How to show distance from the left and right.

I remixed your project to keep the Carry sprite from dropping the phone as it is moved around. I also added a way for it to be let go, just incase that is something that your project needs.

https://scratch.mit.edu/projects/1362412569/
Citrus204
Scratcher
6 posts

How to show distance from the left and right.

I'm still having trouble to keep the phone on a hand once it's held.
10goto10
Scratcher
1000+ posts

How to show distance from the left and right.

My remix of your project has the carrying sprite holding onto the phone while they are being moved.

Powered by DjangoBB