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
Last edited by bynski (2008-01-18 23:54:54)
Offline
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
Offline
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
Offline