PDA

View Full Version : pong actionscript


cxn926
04-14-2005, 12:54 AM
i am making a pong game but i dont know how to make the cpu player follow the ball when i hit it back

help would be great

thanks

Laguana
04-14-2005, 01:14 AM
There are lots of ways to do it, depending on how you want it to be. The easiest way would be to give it the same y co-ordinates as the ball, but that would make it impossible to win. In a pong game i used, I had it set up so that the paddles had inertia, and so the computer player would slide around making it possible for it to miss. You basically need to work out how you want it to be yourself.

Some ideas:
- you can introduce a random element to it's movement speed
- you can make it stop when it's 'close enough' to the ball

cxn926
04-14-2005, 01:18 AM
ok. thanks. i'll just seach it on google

black
04-14-2005, 01:35 AM
the simplest way:

cpuPlayer._y = ball._y;

and if u already had a great method to detect collision this code would work nicely. in fact it will perform such perfect that it is impossible cpu avoid the ball, so to make it more real u may set limitation on velocity to cpu, commonly the velocity is related to cpu's level, higher level cause higher velocity.