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.
|
|
|
|
|
![]() |
||
Setting a veiwing range for a AI character
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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"); } |
|
|
|
#2
|
|||
|
|||
|
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
|
|
#3
|
|||
|
|||
|
Re: Setting a veiwing range for a AI character
Well, that's something
You think it might help if I add my messy FLA file? Last edited by Throntel; Dec 8th, 2006 at 00:18. |
|
#4
|
|||
|
|||
|
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!!
|
|
#5
|
|||
|
|||
|
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? |
|
#6
|
|||
|
|||
|
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.
|
|
#7
|
|||
|
|||
|
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? |
|
#8
|
|||
|
|||
|
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!!
|
![]() |
| Tags |
| actionscript |
| Thread Tools | |
|
|
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 01:09 |
| Updating using a range? | BrokenImage | Databases | 2 | Nov 18th, 2005 14:00 |
| range object | da_stimulator | JavaScript Forum | 0 | Dec 6th, 2004 11:40 |