This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-04-24 14:00:04

Jello715
Scratcher
Registered: 2008-10-11
Posts: 95

Motion mapping?

Can anyone think of an effective way of motion mapping a sprite that moves around?

I'm trying to do this for my robotics team but since I'm unable to attend the meeting today I'm trying to simulate it in scratch :p

Basically, our robot travels a certain path. If the enemy robot gets in its way, we want it to do that same path in reverse so it doesn't start going in the wrong direction. If it does the same thing but reverse, it'll go back to its original starting position and it can try again.

We have special sensors to know if the enemy robot is in front so don't worry about that.

I'm just trying to think of an easy way to make it reverse it's path...

Let's say I have three movement functions. Pressing space bar will be like the enemy robot hitting our robot, so that'll trigger the reverse function.

The three functions..

Go forward for 2 seconds
Go right 3 seconds
Go forward again for 2 seconds

Let's say that the enemy robot "hits" our robot in the middle while going right. Our robot should instantly stop and go left for the same amount of time it went right, then go backwards for 2 seconds. Get it?

I really need help with this! I'm thinking of using a table to track it's movement, but the problem is I need to convert everything to C after.

C has arrays, which is basically like lists in scratch, but I don't think I can add values to it (like adding another item to a list in scratch).

Thank you to anyone who can help me! I really appreciate it  big_smile

Offline

 

#2 2011-04-24 16:49:57

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Motion mapping?

You can do something like this:

http://i56.tinypic.com/2m5dqvb.gif

This stores the robot's positions as it moves forward, then goes to those positions in revers order when the variable "Direction" is anything but "forward."

The only setback to this method is that it will not respond to changes in it's environment (say it's reversing and a wall appears in it's way, it will go through that wall).  To fix this, instead of storing it's positions you can store preset motions it can take.
_________
Motions:  Say you have a motion which you name "Move Forward".  This can be defined as "repeat 10 move 2 steps".  In your robot when you want it to move forward you can do this:
http://i56.tinypic.com/i2ixwy.gif
Now when reversing you can do this:
http://i52.tinypic.com/21jou8x.gif

Except with this method you would have to program in a few set courses of action the robot can take (one being MoveForward, another could be TurnRight, etc.)

Last edited by Kileymeister (2011-04-24 16:55:05)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

Board footer