Free Simple AI Begginer Script

This is a simple script for any beginners who want to use it. Its not very practical, except for simple games. Its a pretty small script, first it finds out who is on your team and who is not, and then based on that It makes decisions. The AI’s will bundle together when they are near each other and run away when they are near someone not on their team. This script is an example of a simple AI that works with out involving things like states and complicated scripts.

################
###          ###
##By: Sunjay03##
###          ###
################

def main():
	GL = GameLogic
	cont = GL.getCurrentController()
	own = cont.owner
	
	#Sensors
	near = cont.sensors['near']
	
	#Actuators
	track = cont.actuators['track']
	
	if near.positive:
		hit_ob_list = near.hitObjectList
		hit_ob = hit_ob_list[0]
		
		if not hit_ob or hit_ob['team'] != own['team']:
			return
		
		#figure out who is on your team.	
		if hit_ob['team'] == own['team']:
			if own['danger'] == False:
	#		print 'team',own.name, hit_ob.name
				if own.getDistanceTo(hit_ob) > 3:
#					print 'HUDLE!'
					track.object = hit_ob
					cont.activate(track)
					own.setLinearVelocity([0,10,0],1)
				
				else:
					cont.deactivate(track)
					own.setLinearVelocity([0,0,0],1)
	
		#if the person in not on your team, RUN AWAY!
		for ob in hit_ob_list:
			if ob['team'] != own['team']:
#				print 'Flee!'
				own['danger'] = True
				track.object = ob
				cont.activate(track)
				own.setLinearVelocity([0,-50,0],1)
				break
			elif ob['team'] == own['team']:
				own['danger'] = False
				continue		
			
	else:
		own.setLinearVelocity([0,10,0],1)
		

main()

Download:
BundleAI.blend (197 KB)

seem like it needs some work but it’s a start, keep developing it.

Yea its just a simple thing just for fun. I wasn’t having alot of luck with complex AI so I decided to start small.

a skool of fish or flock of birds would work perfectly with this

yea. exactly. something simple like that.