Setting a veiwing range for a AI character

This is a discussion on "Setting a veiwing range for a AI character" within the Flash & Multimedia Forum section. This forum, and the thread "Setting a veiwing range for a AI character are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Flash & Multimedia Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Dec 7th, 2006, 14:56
Junior Member
Join Date: Nov 2006
Location: norway
Age: 27
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Setting a veiwing range for a AI character

I've been trying to make some kind of AI for a flash game, now I'm trying to make it attack when I get within a sertant range of it.
I got one problem, when I use the formula written below, I can get closer when closing up from behind than if I'm going from the front. This might sound like a good idea, but since the coordinates doesn't really change when the enemy turns around it's not good at all.

How can I stop this from happening?

-------------------
How I've done it now:


XG, XR, YG, YR and distance are all variables.
XG and YG are the _y and _x coordinates for a green circle.
XR and YR are the _y and _x coordinates for a red circle.
And distance is the range where it will react when you get close.
The "_root.gotoAndPlay("1")" is just something I've used to test if it does react when I get within that range.

if (Math.sqrt((XG-XR)*(XG-XR)+(YG-YR)*(YG-YR))<distance) {
_root.gotoAndPlay("1");
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 7th, 2006, 23:02
Elite Veteran
Join Date: Dec 2005
Location: On Internet
Posts: 4,859
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Setting a veiwing range for a AI character

Man, this is the first post ever, which I could not answer in the flash forum. Sorry, you really have me stuck on this one...lol
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Dec 7th, 2006, 23:06
Junior Member
Join Date: Nov 2006
Location: norway
Age: 27
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Setting a veiwing range for a AI character

Well, that's something Anyone who think they have the answer?
You think it might help if I add my messy FLA file?
Attached Files
File Type: zip AI.zip (14.1 KB, 36 views)

Last edited by Throntel; Dec 7th, 2006 at 23:18.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Dec 7th, 2006, 23:24
Elite Veteran
Join Date: Dec 2005
Location: On Internet
Posts: 4,859
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Setting a veiwing range for a AI character

I will take a look at it, and point some of the other flash guru's over to this forum...We shall see!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Dec 10th, 2006, 19:39
Junior Member
Join Date: Nov 2006
Location: norway
Age: 27
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Setting a veiwing range for a AI character

Alright, it's seems I got the answer.
There was nothing wrong with the actionscript, but both the green and the red circle weren't didn't have their... I don't know what to call it, point zero? at the center. in other words where the Y and X coordinates were calculated from was in the corner of the symbols, not center....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Dec 10th, 2006, 19:51
Elite Veteran
Join Date: Dec 2005
Location: On Internet
Posts: 4,859
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Setting a veiwing range for a AI character

Oh...yeah, I was really amazed, I am an ActionScript guru, and saw nothing wrong with that. Glad you found you answer, I would never of thought of that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Dec 10th, 2006, 22:31
Junior Member
Join Date: Nov 2006
Location: norway
Age: 27
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Setting a veiwing range for a AI character

When I tried make it move I used:

if (_root.attack >= 2)
{
if(YG<=YR&&XG>=XR){
this._x-=fart;
this._y+=fart;
}
else if (YG>=YR&&XG>=XR){
this._x-=fart;
this._y-=fart;
}
else if (YG<=YR&&XG<=XR){
this._x+=fart;
this._y+=fart;
}
else if (YG>=YR&&XG<=XR){
this._x+=fart;
this._y-=fart;
}

This will make the Green circle (YG and XG (YG = Green circle's _y value, XG = Green circle's _x value)) close in on the red circle (XR and YR (same deal as with the Green circle)).
The problem I'm having is that when it does finaly reach this point, it start shaking. I can't get it to stop completely, it looks like it moves a bit too far forward, then realize this and move too far backward then repeat this forever. How can I correct this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Dec 17th, 2006, 06:08
Elite Veteran
Join Date: Dec 2005
Location: On Internet
Posts: 4,859
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Setting a veiwing range for a AI character

Oh, I see the problem...you are doing gaming in flash...hehehe, I know nothing about gaming in flash...lol, maybe someone else can answer this for you!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
actionscript

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling Dropdown based on value range Matc JavaScript Forum 0 Jun 26th, 2007 11:02
Out of range error csun PHP Forum 1 May 6th, 2007 14:16
Creating a character name Throntel Flash & Multimedia Forum 2 Dec 3rd, 2006 00:09
Updating using a range? BrokenImage Databases 2 Nov 18th, 2005 13:00
range object da_stimulator JavaScript Forum 0 Dec 6th, 2004 10:40


All times are GMT. The time now is 08:21.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42