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

#1 2008-01-18 23:54:07

bynski
Scratcher
Registered: 2008-01-18
Posts: 3

Reversing? Going Backwards?

I'm having a bit of script trouble and have been working/searching solutions for a while now. I have a maze-type game, but I would like the Sprite to move backwards one or two steps in whichever direction if came from when it hit the wall. So, say, if I approached a wall heading in the +x direction, I want it to move back two steps in the -x direction.

I can get the sprite to move away from the wall, but I can't make the direction in which it *moves* be opposite (i.e. it will only move away, for example, to the right...and if it still touches the wall it just "drifts away" because it's in a "forever if" loop).

I would appreciate any help with this. Thanks  smile

Last edited by bynski (2008-01-18 23:54:54)


"The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' (I found it!) but 'That's funny ...' " - Isaac Asimov

Offline

 

#2 2008-01-19 03:55:26

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Reversing? Going Backwards?

If you want to simply move backwards then just move -5 or move -10 etc when you touch a wall

To change direction (e.g turnaround) then a simple way is to

   point in direction <direction * -1>

if you are hitting a vertical wall

and

    point in direction <180 - direction>

if you are hitting a horizontal wall

and then move 5 or 10 steps.

You could make the walls different colours so you can tell which action to take.

regards
Simon

I'm sure others will be along with much better solutions soon  smile

Offline

 

#3 2008-01-20 22:59:53

bynski
Scratcher
Registered: 2008-01-18
Posts: 3

Re: Reversing? Going Backwards?

Thanks, I think that will work. I ended up making the main sprite move constantly, and then told it to reverse direction when hitting a black wall in the stage background (as I was trying to minimize number of sprites), which also works. The only thing with that is it  doesn't let you control the speed (as of now, anyway. I might put more time and scripts into it later).

cheers
Robyn


"The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' (I found it!) but 'That's funny ...' " - Isaac Asimov

Offline

 

Board footer