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

#1 2011-03-29 10:08:59

IdozenCair
New Scratcher
Registered: 2011-03-29
Posts: 5

Help! on AI controlled (is it?) moving

I have an issue here which is that I am making a game which you use a paddle to beat the ball towards the bricks and break them (very common). It's just that I don't know how to get the ball to move according to correct physics and bounce back. Can someone help?

Offline

 

#2 2011-03-29 10:16:51

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Help! on AI controlled (is it?) moving

Well, this is hard. Basically, when the ball comes down, you need to negate the direction. I would use point in direction: (direction)*(-1). Also, use [if on edge bounce] for walls. Good luck  wink

P.S. AI means Artificial Intelligence, meaning the computer makes decisions based on the situation. Here, the algorithm is fixed, so it's not AI.

Last edited by Hardmath123 (2011-03-29 10:17:59)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3 2011-03-29 14:56:09

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

Re: Help! on AI controlled (is it?) moving

Hardmath for the most part is correct, though instead of direction*-1, it would work better if you use ((direction*-1)+180).  This makes more realistic turnings.

Edit:  Actually my method is also not completely correct.  Use direction*-1 when the collision is from the sides and (direction*-1)+180 when it's from the top or bottom.
You can do this by making sensor sprites (or a sensor costume).

Make the ball have a separate costume with a certain color on it's left and right and a certain color on it's top and bottom. Make everything else black or some other color.
Like this:http://i56.tinypic.com/2u619ap.gif
(Note:  Make the size of this costume the same as the size of your ball)
Now put a script like this in your movement script for the ball:
http://i54.tinypic.com/sfx8ao.gif
(Note:  This must be put into your movement script, or at least into a forever loop).

Last edited by Kileymeister (2011-03-29 15:40:06)


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

 

#4 2011-03-29 15:39:20

poopo
Scratcher
Registered: 2009-09-20
Posts: 1000+

Re: Help! on AI controlled (is it?) moving

It is not the best looking but work perfectly:
x = x position
y = y position
move <500> steps
If on edge bounce
go to x:<x> y:<y>


http://i45.tinypic.com/28rnqki.jpg

Offline

 

#5 2011-03-31 04:09:50

IdozenCair
New Scratcher
Registered: 2011-03-29
Posts: 5

Re: Help! on AI controlled (is it?) moving

Kileymeister: I'm not sure there's a motion block with only the word 'direction'. Where do you find that?

Offline

 

#6 2011-03-31 04:12:29

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Help! on AI controlled (is it?) moving

IdozenCair wrote:

Kileymeister: I'm not sure there's a motion block with only the word 'direction'. Where do you find that?

You find that in the motion, under the X position and Y position  wink


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#7 2011-03-31 14:45:33

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Help! on AI controlled (is it?) moving

ssss wrote:

IdozenCair wrote:

Kileymeister: I'm not sure there's a motion block with only the word 'direction'. Where do you find that?

You find that in the motion, under the X position and Y position  wink

...at the very bottom  wink

Offline

 

Board footer