ForumsProgramming ForumTargeting Help

2 3523
rytherix
offline
rytherix
68 posts
Nomad

I am trying to develop a new method for NPC targeting, and I was wondering if anyone already had any good systems of doing so that works.
So far I have like this lame detection mc that radiates from the NPC's center, and the first object it hits makes the detecter shutdown and a new mc called the targeter lock onto that new targets x and y. This seems like a real inneffiecient way of doing things and I was wondering if anyone knew a better way. thanks for the help =D

  • 2 Replies
LonLonRanch
offline
LonLonRanch
172 posts
Nomad

Well one thing that might work for you that has worked for me would be to make an onEnterframe statement that checks the object-to-be-detected's x and y values, and if the distance between these two objects is a certain value then you make your action, this might sound confusing, but it is fairly simple, I'll post some example code:
(I'm posting this as a function because I like functions but you could also do it as an onClipEvent(enterFrame) if that is easier)

NPC.onEnterFrame = function() {
this.diffx = (this._x)-(_root.Player._x);
this.diffy = (this._y)-(_root.Player._y);
//These vars are getting the distance between the NPC and the Player

if (this.diffy<=100 && this.diffy>=-100 && this.diffx<=100 && this.diffx>=-100){
//This code here will be what happens if the Player is within 100 pixels of the NPC
}
}

Hope that makes sense, if not let me know

rytherix
offline
rytherix
68 posts
Nomad

ah, I get it, interesing... Im going to try that out, thx
I let you know what my results are

Showing 1-2 of 2