I had some good luck with my question yesterday I thought I'd try hitting up the forum again. I'm teaching a summer class on making games in Scratch right now and I have a student who wants to use path animation. He wants a sprite to follow a specific path her drew as a stage background (although he could just as easily make it a sprite if that's what he needed to do). Is this possible? I know we can do it in PowerPoint but I'd rather not lower myself to using such a tool.
Offline
If I understand the question correctly then yes and there are many ways BUT for your situation (teaching a class) I'm guessing you would prefer the easiest method that works. Can you upload the student's incomplete project? That would help a lot.
Just off the top of my head, you could...
1) Fake the routine to make it looks like it is following the path but I'm guessing the path following really is the point of the project, right?
2) Use color-sensing to read the path and edges of the path and turn the sprite accordingly. Useful if you just have one path whose width remains the same size needed by the sprite.
3) Draw the path using a shape that stamps itself onto the background, moves and turns a little, then repeats. Have your sprite constantly go to the stamp shape and point in it's direction and it will appear to be following the growing path while requiring no pathfinding or extra move scripts at all.
4) Map the entire screen into a list array of 8x8 pixel tiles, each with a value of 0 for "blocking" or 1 for "not blocking." Program the list via a sprite which scans the entire screen, one tile at a time. Create a sprite which follows a set of movement instructions vie nested If statements with logic based on the sprites current direction and the tile data. The tile data must be re-read every time the sprite moves to a new tile.
Ok, that is just getting silly right??? And that is just what I alone thought of off the top of my head, there's no telling how many ways there are. That last one is actually the method I am currently learning in my efforts to redo Pacman as closely as possible to the original.
Last edited by Locomule (2010-07-14 11:47:08)
Offline
I'm pretty sure that you can do this in scratch. I'm not sure how, maybe someone else knows?
EDIT: Oh, Locomule beat me to it.
Last edited by melikecheese (2010-07-14 11:34:45)
Offline
Here is one pretty simple way to make a sprite follow a path: http://scratch.mit.edu/projects/scmb1_prime/1191049
Last edited by scmb1 (2010-07-14 11:56:41)
Offline
Cool idea scmb1! Another 'fake' path finding idea. What I love is that you could easily use this for the foundation of a Replay feature in a project.
Offline
Well, I have made a very accurate Pathfinding AI (here), but it's a little bit too advanced for what you're doing, methinks. So obviously that's not the ideal solution.
I think what Locomule mentioned should do the trick.
Offline
cfunke wrote:
He wants a sprite to follow a specific path her drew as a stage background (although he could just as easily make it a sprite if that's what he needed to do).
Ok, this sentence makes no sense to me and when asking questions in this way you are going to get a lot of jumbled responses.
I am going to assume that what you meant to say is: "he wants a sprite to follow a specific path from a drawing on the stage background picture".
If this is the problem, then the solution is simple.
You need 2 lists, one to record the x positions and 1 for the y positions. Make a script that says this:
when flag clicked
forever if mouse clicked{
add ypostion of mouse to list (yposition)
add xposition of mouse to list (xposition)
}
The will allow the user to draw a "path" which a sprite can follow with the following script:
//this is put on a sprite
when i receive Path{
set counter to 1
{repeat (length of list (yposition)){
go to x: (list xposition (counter)) y: (list yposition(counter))
change counter by 1}
}
Very simple and effective way of doing things, you can see a demo of this method @ http://scratch.mit.edu/projects/archmage/251829
Offline
I guess those would work but he doesn't want the sprite to follow the mouse, he wants to draw it's path and then have it follow it over again. I guess I'm thinking in terms of PowerPoint (Agh!) which allows you to draw the path the object is going to follow and then set a timer for when you want the action to happen.
Offline
cfunke wrote:
I guess those would work but he doesn't want the sprite to follow the mouse, he wants to draw it's path and then have it follow it over again. I guess I'm thinking in terms of PowerPoint (Agh!) which allows you to draw the path the object is going to follow and then set a timer for when you want the action to happen.
That is what will happen. Try out this to see.
Offline
Sounds almost exactly like the project scmb1 linked to in the post above? Technically, it is not a Path "finding" routine, it just appears to be. What it is really doing is recording each new path as a straight line, then having the sprite play back the data by following each recorded path, one after the other.
Again, like just about every thing in Scratch or programming in general, there are many solutions to a single problem. Often times what you find is the realization that you started with the wrong question
Offline
Locomule wrote:
Sounds almost exactly like the project scmb1 linked to in the post above? Technically, it is not a Path "finding" routine, it just appears to be. What it is really doing is recording each new path as a straight line, then having the sprite play back the data by following each recorded path, one after the other.
Again, like just about every thing in Scratch or programming in general, there are many solutions to a single problem. Often times what you find is the realization that you started with the wrong question![]()
Well put.
There are lots of ways to do this on Scratch- the way archmage and I used is just one of the simpler ones. You and your student can modify that method or think of a completely new one.
Offline
OK, I made a project with another method: http://scratch.mit.edu/projects/scmb1_prime/1193415
This one actually uses sensing. A sensor spins around the sprite, looking for the path. The sprite marks the trail it has gone, so it does not go backwards.
It is a bit more complicated and less accurate than the recording method, but it is actually sensing the trail.
Offline
Bravo! It is if the forum were infested with scripting ninja's...
..the wind blows, a leaf rustles, 20 blades silently return...
the birds resume singing.
Offline
OK, yet another way: http://scratch.mit.edu/projects/scmb1_prime/1193618
This is a lot simpler- no trig involved. It works just like the last one except the sensor is attached to the sprite. The only problem is that it is a lot less accurate. For some reason, it is better offline.
Last edited by scmb1 (2010-07-15 14:25:43)
Offline