Discuss Scratch

tennis89
Scratcher
14 posts

game [move without touching other sprites?]

How do you make something float around but not bump into other sprites?

Last edited by Paddle2See (Oct. 6, 2014 17:37:20)

lederniersamourai
Scratcher
500+ posts

game [move without touching other sprites?]

That is a good idea for a game.
To do that you have to check IN ADVANCE that you will not bump before moving your sprite.
An easy solution is to associate a phantom sprite that is one step ahead to the real character sprite.
You move the phantom. If it bumps, you move it somewhere else. If it does not bump, then you move your character exactly at the same place of the phantom.
Note that you should use the special effects to make your phtantom with transparency put to 100%
theonlygusti
Scratcher
1000+ posts

game [move without touching other sprites?]

The above answer will work, but I have a way that only uses 1 sprite.

Basically, you move the sprite forwards, and then if it is not touching anything, you leave it there, otherwise move it back and turn around. E.g.
set [berth v] to (7) // this is the amount of pixels you will leave around each obstacle
set [speed v] to (7) // this is the speed your sprite will move around at. It must be less than berth, preferably the same as.
forever
move (berth) steps
if <not <touching [obstacle v]>> then
move ((0) - (berth)) steps
move (speed) steps
else
move ((0) - (berth)) steps
turn cw ((15) * (pick random (-1) to (1))
end
end

Obstacle could be a color, or another sprite, and the sprite with this script inside it will move around randomly without touching the obstacle.

Powered by DjangoBB