Last visit was: It is currently Sun Sep 05, 2010 8:57 am


All times are UTC


Forum rules


Please use brackets in topic titles to show what language your topic is about. Ex. [C++] [GML]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [GML]Help me improve my AI
PostPosted: Wed Apr 07, 2010 4:03 am 
Site Admin
User avatar

Joined: Tue Sep 22, 2009 12:35 am
Posts: 52
This is my AI code:

Code:
if distance_to_object(argument0) > 75 {
if distance_to_object(argument0) < 150 {
    attack=1
}

if distance_to_object(argument0) < 100 {
if shoot=1 {
    instance_create(x,y,argument1)
    alarm[0]=argument3
    shoot=0
}
    speed=0
}
}

if distance_to_object(argument0) < 50 {
    speed=0
    attack=0
}

if distance_to_object(argument0) < 175 {
    image_angle=point_direction(x,y,argument0.x,argument0.y)
}

if distance_to_object(argument2) < 25 {
if distance_to_object(argument0) > 75 {
    attack=1
}
}


//arg0: Player obj name
//arg1: Bullet obj name
//arg2: Player bullet obj name
//arg3: Shoot timer
//arg4: Name of obstacle obj. (Ex: wall)

//Include in Create event:
//shoot=1
//attack=0
//image_angle=random(360)

//Include in Step event:
//basic_ai(arg0,arg1,arg2,arg3,arg4)


It's pretty horrible lol. I'm just asking for simple little tweaks or additions that can make AI more real, or fun to play against.

_________________
Image


Top
Offline Profile  
 
 Post subject: Re: [GML]Help me improve my AI
PostPosted: Fri Apr 09, 2010 2:41 pm 
User avatar

Joined: Sat Oct 03, 2009 3:14 am
Posts: 46
Location: Far, far away
All right, for one thing, you are calling a fairly slow function distance_to_object(argument0) over and over again. You can remedy this with a variable at the start.
Secondly, I don't think these guys have infrared goggles, so add a check to see whether or not they can actually see you.
And, I'm not 100% sure it'll work completely properly, as I am now at school, but I added a bit of code that allows the npc to pace around if it doesn't see the player. When I get home, I will test it out.

Remember to replace the following line with the info it asks for:


*I've tested this and it doesn't work properly. I'm working on it...*

wall_id = [whatever the wall is called]

Code:
var dist, wall_id, canseeplayer, angle, angle2, x2, y2, pace_buffer;
pace_buffer = 40
angle = floor(random(4))
x2 = pace_buffer
y2 = 0
wall_id = [whatever the wall is called]
dist = distance_to_object(argument0);
canseeplayer = ( collision_line(x,y,argument0.x,argument0.y,wall_id,false,true) == 0 )

if canseeplayer {
if dist > 75 {
if dist < 150 {
    attack=1
}

if dist < 100 {
if shoot=1 {
    instance_create(x,y,argument1)
    alarm[0]=argument3
    shoot=0
}
    speed=0
}
}

if dist < 50 {
    speed=0
    attack=0
}

if dist < 175 {
    image_angle=point_direction(x,y,argument0.x,argument0.y)
}

if dist < 25 {
if dist > 75 {
    attack=1
}
}
}
else
{
image_angle =  angle * 90
if collision_line(x,y,x+x2,y+y2,wall_id,false,true) == 0
{
x += x2 / 20
y += y2 / 20
}
else {
angle2 = floor(random(4))
if angle == angle2
angle2 += 1
if angle2 == 4
angle2 = 0
angle = angle2

x2 = 0
y2 = 0
switch ( angle ) {
case 0 : x2 = pace_buffer break
case 1 : y2 = pace_buffer break
case 2 : x2 = pace_buffer break
case 3 : y2 = pace_buffer break
}

}

}

//arg0: Player obj name
//arg1: Bullet obj name
//arg2: Player bullet obj name
//arg3: Shoot timer
//arg4: Name of obstacle obj. (Ex: wall)

//Include in Create event:
//shoot=1
//attack=0
//image_angle=random(360)

//Include in Step event:
//basic_ai(arg0,arg1,arg2,arg3,arg4)

_________________
Image Image
My Runescape user name is Sir Kaslai...
Join me!


Top
Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net & kodeki
Localized by MaĆ«l Soucaze © 2010 phpBB.fr