# How to make a slingshot in Hopscotch?

Hi, long time no see!
I’m curious on how you would make a slingshot in hopscotch? I have this game idea, and I’d really like to try out how to make a slingshot
(I also searched before I posted, there are no topics explaining how to make one)

14 Likes

A slingshot is not too terribly difficult. I’ll try to explain.

You’ll need 2 objects, the sling and the shot. (Not official names for a slingshot but whatever). The shot is what the user drags and the sling is what stays in one spot.

When the user presses the shot, set a variable to 1. I’d call it “Touch” or something of the sort.

Then do a block for `when Touch == 1`, do a `set Touch to 0`. Then do a `wait 10`, and check if it is still equal to 0. Do that 3 more times, so that the `check if` blocks are in one another. Then in the last `check if Touch == 0` do `set Touch to 2`.

Now, when Touch == 2, that signifies the end of the touch. Cool.

Do a `when Touch == 2` block. Inside of that, set a variable on the shot named something like ‘X Verlocity’ to the Sling X position - the shot x Position, then divide that by 5 or something so it’s not super powerful. Do the same for the Y. Then, set it’s State or some variable to 1.

Now, make a `when State == 1`. Inside of that do a Set Position block, and set the X to `x velocity + x position` and the y to `y velocity + y position`. Wham. Now the shot moves when you drag it back.

For gravity, just make another `when State == 1` block, and put a `increase y velocity by -1` block in that.

If you want to reset the slingshot, just set it’s State to 0, and then put the position to wherever the sling is located.

And if all this doesn’t make too much sense (I know, it’s a lot) check out this project I made a while ago:

10 Likes

Thank you! I’ll try to use this

1 Like

Oh yeah and I forgot to mention, after you set the touch to 2, set it back to 0. 0 basically means it isn’t being touched.

1 Like