LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 


Prev Previous Post   Next Post Next
  #1  
Old 05-09-2006, 06:22 PM
gamalielrt gamalielrt is offline
Registered User
 
Join Date: Apr 2006
Posts: 4
Rep Power: 0
gamalielrt is on a distinguished road
Fix Continuous Turning

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.
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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




All times are GMT. The time now is 03:26 PM.