|
-
actions activated by measure
hey guys,
i was wondering, is it possible for an action to be
pulled off by distance from a certain object?
say my hero is like 60 away from the enemy (60 in terms of _x)
and if my hero is within 60x from the enemy, then
the enemy will attack
if my hero is farther than 60, then do something else...
is that possible?
if so, can anyone show me how this is done?
thnx a lot, erhm, a bunch!
"Are those gummy worms? Can I have some?"
"Nevermind, I just saw one move by itself..."
-
Senior Member
code:
//On the enemy
if(Math.abs(this._x)<heroDist){
attack();
} else{
walk();
}
The Math.abs part ensures that the hero can approach from left or right. Does this help?
-
htnx dude! I think i get your idea
Math.abs, its like saying that the number is
both negative and/or posistive right?
oh and, how do i specify the distance from the hero?
anyhoo, thnx a bunch!
"Are those gummy worms? Can I have some?"
"Nevermind, I just saw one move by itself..."
-
Senior Member
Yeah, Math.abs is the absolute value, which means positive or negative. Sorry, I messed it up and forgot a section! I can't believe it... sorry.
Anyways, should read:
if(Math.abs(this._x-hero._x)<heroDist){
heroDist would be the distance away from the hero where the enemy would start to do something. In your example, this would be 60. Sorry for the screw up
-
x2i
I used two movie clips, one named mc1 and the other mc2, then i used this code in the frame.
Code:
_root.mc1.onEnterFrame = function() {
xDist = Math.abs(Math.round(_root.mc1._x-_root.mc2._x));
if (xDist<60) {
trace("ATTACK!!!");
}
};
It checks how far mc1 is from mc2, rounds it up to a postive and round number, then you can check to see how far away it is.
Hope it helps
-
oh hey St. Nick, dont worry bout it!
thnx for the help you guys, now i have a
good start off with my AI!
"Are those gummy worms? Can I have some?"
"Nevermind, I just saw one move by itself..."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|