Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums [AS3] pong funtime
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 12-03-2010, 02:46 AM #1 flips30240 Registered User   Join Date: Dec 2009 Posts: 44 [AS3] pong funtime hello all ( again ) im making a pong game where one of the paddles are ai controlled(correct term usage? probably not) the code i have for that is function ai(event:Event) :void { paddlepart1.y = ball.y + 19; paddlepart2.y = ball.y - 19 } (i made the paddle of 2 dif pieces to control if the ball will bounce of it at an upwards or downwards angle, im sure theres an easier way to do that but i dont know it lol) the paddle halves are 38 pixels each so hence the - + 19. ok SO now to my dilema, the paddle will get to the ball every time, maiing the game impossible to win, i want to slow the paddle down but i dont now how to add a speed variable into it. any suggestions?
 12-03-2010, 03:19 AM #2 malarr Registered User   Join Date: Dec 2010 Posts: 6 don't use ball += 19, instead try using a variable like xSpeed and ySpeed then create a random number that will change the speed.
 12-03-2010, 03:25 AM #3 Kritjon Senior Member     Join Date: Oct 2009 Location: Beijing, China Posts: 244 Just give the paddle a maximum speed. ActionScript Code: ```const PADDLE_SPEED = 10; function ai(event:Event):void {     if ((Math.abs(paddle.y - ball.y)) < PADDLE_SPEED) {         paddle.y = ball.y;     } else if (paddle.y < ball.y) {         paddle.y +=  PADDLE_SPEED;     } else {         paddle.y -=  PADDLE_SPEED;     } }```
 12-03-2010, 03:51 AM #4 flips30240 Registered User   Join Date: Dec 2009 Posts: 44 love the quick responses here =) ill give that a shot =3
12-03-2010, 04:11 AM   #5
flips30240
Registered User

Join Date: Dec 2009
Posts: 44

Quote:
 Originally Posted by Kritjon Just give the paddle a maximum speed. ActionScript Code: ```const PADDLE_SPEED = 10; function ai(event:Event):void {     if ((Math.abs(paddle.y - ball.y)) < PADDLE_SPEED) {         paddle.y = ball.y;     } else if (paddle.y < ball.y) {         paddle.y +=  PADDLE_SPEED;     } else {         paddle.y -=  PADDLE_SPEED;     } }```
alright you lead me to the right track track with the if(paddle.y < ball.y) and if(paddle.y > ball.y) which resulted in the finished and working code of

ActionScript Code:
```function ai(event:Event) :void {
}
}```

huge thanks, its funny how simple something seems once the solution is in front of you =3

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home ActionScript Forums Group     ActionScript 3.0     ActionScript 2.0     ActionScript 1.0 (and below)     Simple Stuff (Newbies) Flash General Questions     Flash 10 General Questions     Flash 9 General Questions     Flash 8 General Questions     Other Flash General Questions Flex     Flex 2, 3 & 4     Flex 1 Extensions and Plugins     Components     JSFL - Extending Flash Desktop, Mobile and non-browser Environments     AIR (Apollo)     FlashLite / Portable Devices Development     Projectors and CDs Supporting Technologies     HTML and JavaScript     haXe     Server-Side Scripting     Flash Remoting     Flash Media Server General     Best Practices     Gaming and Game Development     Animation and Effects     Flashants Support Forum Community Boards     General Chat     Just for Kicks Challenges     Detention Flash In Action     Site Check     Cool Sites     Widgets Decommissioned     Projects and Positions CMS Forums     Announcements Board     Content Postings / Updates     Product Review Requests     CMS Technical Questions     Process Questions     Collaboration & Suggested Articles

All times are GMT. The time now is 02:09 AM.

///