
Welcome Guest
|
#1
|
|||
|
|||
|
Hi, I am fairly new to AS. I have a game where you kick the football around and try to score but I am having trouble programming the AI.
What I want him to do is always go towards the ball. But when the angle of the ball to him is over 180 degrees or under -180 he has to turn round the other way. He does this because he is programmed to add 6 to his degrees the angl of him to the ball is bigger then his rotation and visa versa. But when the ball crosses fromm 180 degrees to -179 he has to rotate the other way. Here is the code: Actionscript:
//CPU Player
function checkKeys1() {
//makes CPU go forward
accel1 = 0.85;
//turn1 is the CPU's rotation
walk1._rotation = turn1;
rad1 = walk1._rotation*Math.PI/180;
velx1 += Math.cos(rad1)*accel1;
vely1 += Math.sin(rad1)*accel1;
walk1._x += velx1;
walk1._y += vely1;
velx1 *= 0.85;
vely1 *= 0.85;
//this works out the angle from the CPU to the ball
radians = Math.atan2((_root.ball._y-_root.walk1._y), (_root.ball._x-_root.walk1._x));
//this puts it into degrees
ballDegrees = Math.round(radians*180/Math.PI);
//when the angle of the CUP to the ball is bigger then it's rotation
if (ballDegrees>turn1) {
//it adds 6
turn1 += 6;
}
//when the angle of the CUP to the ball is less then it's rotation
if (ballDegrees) {
//it subtracts 6
turn1 -= 6;
}
}And a link to the file: http://homepage.ntlworld.com/michael...allhouse1.html Hope you can help. |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Continuous moving graphic background | jadefox | Newbies |
2 | 08-18-2007 12:29 AM |
| How to create Page Turning Effect in Flash | Sido | Flash MX 2004 |
1 | 02-15-2006 12:51 PM |
| Continuous Scrolling button action? | marll | Flash MX 2004 |
1 | 06-02-2005 12:17 PM |
| continuous looping background | Wouthor | Flash MX ActionScript |
4 | 09-04-2003 03:49 PM |
| continuous background | abeuw | Flash 5 Actionscript |
1 | 09-28-2001 06:27 AM |

Programming Languages



