Discuss Scratch

leelee100
Scratcher
1 post

How to stop in the middle of a glide

i want help on how to make a spite glide in a different direction to were it was gliding before. the trouble is that when gliding it sort of locks down the sprite until the end of the glide.
cobraguy
Scratcher
1000+ posts

How to stop in the middle of a glide

I don't think you can stop a sprite in the middle of a glide. You have to wait till it's done.
andre_rifaut
Scratcher
100+ posts

How to stop in the middle of a glide

Well, this could be difficult.
But you can try as follows:
a) clone the sprite,
b) hide the (main sprite)
c) define two “when I start as a clone”, one ofthem with the glide, the other one with a “wait until …(come condition) ” both ended by “delete this clone”
d) in your main sprite, just makes the “some condition” true before the end of the glide
e) show the main sprite at the end.
e) Cross your fingers.
dracae
Scratcher
1000+ posts

How to stop in the middle of a glide

Instead of using glide, you can use and .
These are more reliable and flexible. (In my opinion)
If you used those, you could stop in the middle of whatever.
Hope this helps!
owwo
New Scratcher
2 posts

How to stop in the middle of a glide

Use and? Can you clarify what you mean?
MCAnimator3D
Scratcher
500+ posts

How to stop in the middle of a glide

Do this:

defineStopglideifactionatspeed:speedAction is a boolean input (block with pointy ends)repeatuntilactionmovespeedstepsDo this until it does the actionaction is supposed to be purple and with pointy ends
scubajerry
Scratcher
1000+ posts

How to stop in the middle of a glide

It is easy. Look at this project.
owwo
New Scratcher
2 posts

How to stop in the middle of a glide

Thanks guys, you both were very helpful.
JsnPrkr
Scratcher
100+ posts

How to stop in the middle of a glide

Despite the somewhat misleading title, the original poster asked about…

leelee100 wrote:

…how to make a sprite glide in a different direction to where it was gliding before…

Since first seeing this last week and having no idea then how to stop or change a glide, I programmed a game called "Super Shot Soccer" that redirects the soccer ball in the middle of a Glide. I programmed overlapping Glides in just to see what would happen and it was sheer luck that it worked. You can see the Glide behavior when the player and the defender kick the ball back and forth. Turns out that the result is dependent on the glide time setting of the current and new Glide commands and how much glide time is left on the interrupted Glide command. I remixed the StopScript experiment in ScubaJerry's post above to show how a new Glide instruction interacts with one that's currently underway. Experiment with it in the remix project HERE. Some principles about interrupting and redirecting glides are in the project notes.

To redirect a glide, issue a second Glide command to the new destination. To stop a glide, trigger a new Glide to the sprite's current position (this is what the space bar does in the remixed experiment project). Note that this has to be done in a script other than where the original Glide block is–unless the structure below is used.

There's an interesting and clever method of stopping a Glide HERE. It uses a second script that stops itself under a certain condition. The subroutine nature of the second script solves the execution thread complication and could also be used to redirect a Glide. Probably using a counter to keep track of which pass through the sub-script would do the trick: (Change <Pass> by 1, if <Pass>=1, Glide and Change <Pass> by 1, else Set <Pass> to 0 and StopScript) would toggle motion and stopping. <Pass> could be re-set to zero to invoke a second Glide. Looks like the basis for a useful CustomBlock.

Last edited by JsnPrkr (Jan. 18, 2014 10:54:33)

SCRATHCREATOR950
Scratcher
12 posts

How to stop in the middle of a glide

here is the answer it is so easy
whenclickedglide1secstox:randomnumbery:randomnumber
Paddle2See
Scratch Team
1000+ posts

How to stop in the middle of a glide

SCRATHCREATOR950 wrote:

here is the answer it is so easy
whenclickedglide1secstox:randomnumbery:randomnumber
That's a great way to send a sprite gliding off to some random point,.but it won't stop a sprite that is already started on a glide.

A way that will work, though, is to use the Stop block
whenIreceiveStop Glidingstopother scripts in sprite
scubajerry
Scratcher
1000+ posts

How to stop in the middle of a glide

Paddle2See wrote:

SCRATHCREATOR950 wrote:

here is the answer it is so easy
whenclickedglide1secstox:randomnumbery:randomnumber
That's a great way to send a sprite gliding off to some random point,.but it won't stop a sprite that is already started on a glide.

A way that will work, though, is to use the Stop block
whenIreceiveStop Glidingstopother scripts in sprite
Yep - that is what I said 2 months and 1 day ago.
wcender
Scratcher
43 posts

How to stop in the middle of a glide

Actually, the easiest way is to avoid using glide.
annthony
New Scratcher
1 post

How to stop in the middle of a glide

Hi Guys I have similar problem. I have designed a simple game where a cat jumps up and must try not to land on a tennis ball which glides from left to right of the screen when it lands. The idea is that if the cat lands on the ball then the tennis ball stops gliding. So basically when the cat ‘script 1’ touches the tennis ball ‘script 2’ it should stop gliding left to right. Have tried everything but the ball glides continuously from left to right. I have tried the obvious things like ‘if touching script ’ STOP but it just goes on and on. Any suggestions.

dhubler
Scratcher
1 post

How to stop in the middle of a glide

i found a hack that worked for me. To stop a glide for 1 second add
glide for 1 secs to x: (x position) and y: (y position)
which will glide the script to it's already current position
PffN
Scratcher
23 posts

How to stop in the middle of a glide

Paddle2See wrote:

SCRATHCREATOR950 wrote:

here is the answer it is so easy
whenclickedglide1secstox:randomnumbery:randomnumber
That's a great way to send a sprite gliding off to some random point,.but it won't stop a sprite that is already started on a glide.

A way that will work, though, is to use the Stop block
whenIreceiveStop Glidingstopother scripts in sprite
But how do you program the random x and y?
JsnPrkr
Scratcher
100+ posts

How to stop in the middle of a glide

Maybe I wrote too much back in January 2014 for the message to get through… Here's another try:

You can change the direction or speed of a Glide with a new Glide instruction.

One way to stop a glide in the middle is to execute a new glide instruction to the sprite's current position. The trick to this method is to make the new Glide time long enough to keep the sprite in place long enough for the original Glide time to complete/expire.

The following code starts a Glide and then changes direction with a second Glide and then jumps back onto the first Glide's path. This is not normally what you'd want to do.

glide5secstox:0y:0wait1secsglide2secstox:100y:100

This code will make a smooth direction change:
glide5secstox:0y:0wait1secsglide4secstox:100y:100

The “mechanics” of the Glide command's behavior are posted in the notes for THIS PROJECT. The project is designed to show the interaction of having more than one Glide command active at a time.

The comments after my original post show that the concepts in my original post were missed somehow. Many people have viewed the project though only ScubaJerry commented on it. Was it unclear or something? Please leave me a comment at the project if there's something that you don't understand. I'll be happy to break it down to basics.

P.S. General advice to all is to avoid saying something is “easy”–unless you're talking to a customer or your boss. If you feel like bragging on yourself, just create and share great projects to show off your abilities. Let the people who come here to learn new things make their discoveries with as few unnecessary distractions as possible. Scratch is a place of learning and should therefore be about the student's experience.

P.P.S. In programming, most things are SIMPLE, but not necessarily “easy”. A wise person knows the difference. Something is only “easy” to those who can already do it. A back flip is simple and looks easy when done by someone who already knows how it's done and has worked to develop the skill required to do one. What you don't see is the hours of hard work, practice, and thought that got them to the point of being able to make it look easy. Have some consideration for the posters who come here for help–and for the folks who come to share their ideas. The wise man also knows it's usually best to check your ego at the door before you enter.

Last edited by JsnPrkr (Jan. 7, 2015 18:21:55)

bumpjammy
Scratcher
100+ posts

How to stop in the middle of a glide

you will have to do two separate glides for eg:

whenclickedglidesecstox:0y:0waitsecsglidesecstox:0y:0
Cllawgraber
Scratcher
43 posts

How to stop in the middle of a glide

How about this…

whenclickedglidehowevermanyyouneedsecstox:whereveryouwanty:whereveryouwantbroadcaststop me gliding!stopthis scriptwhenIreceivestart gliding somewhere elseglidehowevermanyyouneedsecstox:whereveryouwanty:whereveryouwant

… will that do?

Cllawgraber

Last edited by Cllawgraber (May 24, 2015 18:22:10)

Peter-E
New Scratcher
1 post

How to stop in the middle of a glide

After reading through the various suggestions in this post, I came up with this experiment which has Sprite 1 continuously and randomly glide through the area - until it collides with Sprite 2.

Even if the collision occurs “mid glide”, the glide is immediately stopped, Sprite 1 is moved to its initial position (alternatively and just as easily, you could have it change direction) and the process starts over.

For me, this seems an elegant solution for both the “collision detection” as the “instantly change direction/location even while in the middle of a glide” scenario's that many games will need to solve.

However, having learned about Scratch about 2 hours ago, I am very much interested in feedback.

You can find the project here.

Powered by DjangoBB