Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: AI Help  (Read 1141 times)

0 Members and 1 Guest are viewing this topic.
AI Help
« on: January 03, 2008, 04:13:31 am »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
Well I'm working on a LOG2 AI, first off I need help on the movement, heres what I have.

Create Event:
Code: [Select]
dir="d"
follow_hero=true
image_speed=0.2
movespeed=2
near_hero=false
Step Event:
Code: [Select]
if point_distance(x,y,obj_hero.x + 2,obj_hero.y + 3) < 2
speed = 0
else
if point_distance(x,y,obj_hero.x + 2,obj_hero.y + 3) < 228{
follow_hero=true
move_towards_point(obj_hero.x +12,obj_hero.y +3,movespeed)
}
if point_distance(x,y,obj_hero.x + 2,obj_hero.y + 3) > 229{
hspeed = 0
vspeed = 0
follow_hero=false
}
else {
if point_distance(x,y,obj_hero.x,obj_hero.y ) < 48 {
hspeed = 0
vspeed = 0
follow_hero=false
}}

depth =-y
Begin Step:
Code: [Select]
if follow_hero=false
{
if dir="d" {
sprite_index=sprite_index=spr_goku_s_d
}
if dir="r" {
sprite_index=sprite_index=spr_goku_s_r
}
if dir="l" {
sprite_index=sprite_index=spr_goku_s_l
}
if dir="u" {
sprite_index=sprite_index=spr_goku_s_u
}
}
End Step:
Code: [Select]
if follow_hero=true {
var n;
n = radtodeg(arctan2(ai_goku.y-obj_hero.y,obj_hero.x-ai_goku.x));
if (n < -135 || n >= 135)sprite_index=spr_goku_l
if (n >= -135 && n < -45)sprite_index=spr_goku_d
if (n >= -45 && n < 45)sprite_index=spr_goku_r
if (n >= 45 && n < 135)sprite_index=spr_goku_u
if sprite_index=spr_goku_l then {
dir="l"
}
if sprite_index=spr_goku_d then {
dir="d"
}
if sprite_index=spr_goku_r then {
dir="r"
}
if sprite_index=spr_goku_u then {
dir="u"
}
}
User Defined 0:
Code: [Select]
dir=point_direction(obj_hero.x,obj_hero.y,x,y)
The User Defined is supposed to use the variable dir and control the movement but it never gets called... anyways is there solutions in simplifying all of this code into the step event, and the code size is allot smaller?

and also since I use other objects for my battle system is it possible using variables? cause I tried it but the ai never moved unless I did it with obj_hero.x or .y

Heres a vid I took from LOG2 and it's AI
http://youtube.com/watch?v=DgLI0QYfjYg
Logged
Re: AI Help
« Reply #1 on: February 29, 2008, 10:44:30 pm »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
Bump
Logged
Re: AI Help
« Reply #2 on: March 01, 2008, 12:06:14 am »
  • Fear my Blades
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 562
If I read correctly the codes all working, and you just want to optimize it some right?  I'll have a look through it when I have the time.

For it to still react to the player when his object index is changed by the battle system, you could either store the player's id to a global variable that the AI uses, or create a 'parent' object for the player.  I'd probably go with the latter so if I decide later that I want the AI to attack other objects the same way it does the player I can just use the parent object.

To create a 'parent' object for things the AI attack:

1) Create a new object, but don't give it any events.  Name it something like obj_AItarget or whatever you want, as long as you know what it's for.

2) Under the object properties for all of the objects you want the AI to attack, theres an option "Parent" with a drop-down box on the left side of the window.  Under this select the object you just created.

3) Edit your AI code to go after the parent object.



One of the many uses of parents.  Be aware though that if you do give the parent object events any object that has them as a parent inherits those events unless they have their own of the same type.  This can be a very useful if you have several objects that use most of the same code, but it can also be confusing, and cause odd, hard to find bugs if you don't realize it's happening.
Logged

I've done it (sorta)!  Bloom Lighting in GameMaker, and 3D mode too!  Check out the awesome Screen Saver.
  • Kousou Games
Re: AI Help
« Reply #3 on: March 06, 2008, 01:08:03 am »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
Ok I'm having another problem, my ai objects are joining... I tried "mp_potential_step_object(x,y,stepsize,obj)" but it didn't work... I'm trying to make it like that video.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.285 seconds with 42 queries.