Clicking/Snapping in Hopscotch

hopscotch
help

#1

Is there a way to make something click or snap in Hopscotch for pressing? Like when a character in Hopscotch stops at certain places. I'm talking about x and y, not only one of them (because you can only check once if for one of them) and without having them repeat to stay at a position because the item you're pressing will stay there, wouldn't it? And the characters snap at a certain distance from the place it clicks, not random places within the radius. Or am I wrong?


#2

This post was flagged by the community and is temporarily hidden.


#3

You know how the characters in Hopscotch stop in certain places when you drag them, even when the characters are 10 pixels away or more from that place in edit mode? I mean that.


#4

Well... You could use check onces, but you'd be doing around 100 of them.


#5

This post was flagged by the community and is temporarily hidden.


#6

Do you mean the thing that happens in edit mode where something will snap into a certain position? Like if you are trying to get a certain position but it snaps somewhere else a couple things away?


#7

Yes, I mean that. I can't explain some stuff clearly at all.


#8

But what if the character was in 0 for the X position, but wasn't in 20?


#9

Alright, so now that I know what you're talking about what was the question you were asking?


#10

If there was a way to create it in Hopscotch. The rest of it was giving problems with some ideas I knew others were going to post, but some of what I said could've been wrong.


#11

This post was flagged by the community and is temporarily hidden.


#12

But the changing y by wouldn't even occur since the check once if says not equal to 0, then change y, and the position would be equal to 0.


#13

Hi @GysvANDRegulus I'm not sure if this is what you were looking for but I was thinking about making a tutorial for how to snap to a position. Here is a test project https://c.gethopscotch.com/p/y3uw8ob0m

I could post the tutorial here if it's relevant to what you were asking, so others who search can find it here too, or I can make a new topic. Either way, people will be able to search it up so it doesn't matter too much :)


#14

Yes, it is what I was looking for!
For some reason I don't remember ¯\_(ツ)_/¯

You can post the tutorial here if you'd like to!


#15

Awesome!

Here's a picture of the code (edited so you can see all of it):


Again the project is here https://c.gethopscotch.com/p/y3uw8ob0m

I'll focus on the "Snap to position" ability. So if you want an object to detect if it is within a distance, it's easiest to use Pythagoras' theorem to work out its distance first.

distance = √(a² + b²)

You'll see the √(a² + b²) part in the Check Once If which works out the distance of the circle, from the point (500,300). You just need to replace those numbers (500,300) with whatever coordinates you like.

a = 500 - x position
b = 300 - y position

The Check Once If then checks if that distance is less than 75.

If that's true, then it will make the object go straight to that position, looking like it has "snapped" itself to that position. And that's all you need for the "snapping" part.

Usually you want the object to snap after you let go of it or release it, so that's what the rest of the code is for. The code for when an object is released is explained really well in the Angry Birds video tutorial if you want to make that part too.

The video automatically starts at the point 8:58 (the part about releasing an object goes until 15:00.)

(I did it a little differently to the video, using code from other Hopscotchers.)