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

#1 2013-01-21 12:46:22

redragon
Scratcher
Registered: 2010-07-05
Posts: 10

How do you stop a ball going through a line?

I am creating a game and I need to know how to make sure the ball doesnt go through the lines on the level.

            l
.>>>>>>>l>.                  .=ball                 l = wall or line         >>>= movement of ball
           l


Please help. Thank you
cool

Offline

 

#2 2013-01-21 12:49:27

iaoumeur
Scratcher
Registered: 2012-11-24
Posts: 500+

Re: How do you stop a ball going through a line?

Look at a platformer base and download it.
Here is an example: http://scratch.mit.edu/projects/Vortex_/2902627


The Dot 3 is out!!! Play it here!

Offline

 

#3 2013-01-21 13:22:42

redragon
Scratcher
Registered: 2010-07-05
Posts: 10

Re: How do you stop a ball going through a line?

Which part of the script should I look at?
hmm

Offline

 

#4 2013-01-21 13:49:17

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

Re: How do you stop a ball going through a line?

I assume you mean the problem where a ball moves a larger number of steps than the thickness of the line, and thus passes through it?

It can be annoying, but one of the most reliable methods is to convert move (x) steps into individual single steps.

Thusly:

when gf clicked
forever
if <not <touching [ground]?>>
move (10) steps
end
Becomes:
when gf clicked
forever
if <not <touching [ground]?>>
move (1) steps
if <not <touching [ground]?>>
move (1) steps
if <not <touching [ground]?>>
move (1) steps
if <not <touching [ground]?>>
move (1) steps
if <not <touching [ground]?>>
move (1) steps
end
It takes more time to code it like that, but this way it checks every individual step on its path (it will still move at the same speed though, because all those steps are checked within the same frame).

Last edited by Kileymeister (2013-01-21 13:50:25)


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

 

#5 2013-01-21 13:59:31

redragon
Scratcher
Registered: 2010-07-05
Posts: 10

Re: How do you stop a ball going through a line?

I'm saying that when I press the arrow keys, the ball doesn't stop when it's hitting a wall and goes through. How do I get it to stop and disable its movement even when an arrow key is being pressed?

That said, thank you very much for your help.
big_smile

Last edited by redragon (2013-01-21 14:00:24)

Offline

 

#6 2013-01-21 14:53:50

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How do you stop a ball going through a line?

redragon wrote:

I'm saying that when I press the arrow keys, the ball doesn't stop when it's hitting a wall and goes through. How do I get it to stop and disable its movement even when an arrow key is being pressed?

That said, thank you very much for your help.
big_smile

Well, there are a few ways, though before I show you, could I see you scripts so that I could get you the best answer?


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2013-01-21 15:10:31

redragon
Scratcher
Registered: 2010-07-05
Posts: 10

Re: How do you stop a ball going through a line?

I cant show you my scripts. Sorry. There is some code in there that I dont know how to write. Plus, it is VERY long. Do you have any tips that might be able to help me?

Thanks for helping,
- Redragon  cool

Offline

 

Board footer