Copy link to clipboard
Copied
what i whant is when any of the units get to a certain distance of the enemy it should trace(shoot).
can anyone help me...............
................................................................................
var unitA:Array=[unit,unit1,unit2];
var c;
var s;
var deltaX;
var deltaY;
var dist;
var range;
_root.onEnterFrame = function() {
var unit = unitA;
c = _root.unit;
s = _root.enemy;
deltaX = c._x-s._x; deltaY = c._y-s._y;
// rounded distance
dist = Math.sqrt((deltaX*deltaX)+(deltaY*deltaY));
}
function rangetoshoot(){
if(unit.dist >= 100);
trace(shoot);
}
.........................................................................................................
The code you show is incomplete at best. And you still do not have anything that loops thru the array to check each unit. The undefined could be pointing at your lack of defining a value for i, though it could also be that you haven't define a value for shoot. If shoot is not a variable and your intention is to display the word "shoot", then you need to use quotes
Copy link to clipboard
Copied
The code is not right and not a clear indication of intentions. Are you familiar with using loops? If not, you need to learn about them so that you can test each unit to see if it is where you want it to be to trace. Also, you need to use a conditional... your rangetoshoot function has one, but your code doesn't call that function. Also, I am not sure if you are testing for the right condition, so just fair warning... it will trace only when the unit is farther than 100, not less than.
Can you explain what the units are that you are using in these lines of code?
var unit = unitA;
c = _root.unit;
because _root.unit will not be that same as the "var unit" you just assigned.
Copy link to clipboard
Copied
ahh ok i whant it to trace when i am 100 are lower. well im using the units(unit,unit1,unit2) from my array and i thought this unit linked with this one
var unit = unitA;
c = _root.unit;
Copy link to clipboard
Copied
For the lower than you would use <=
If you want that unit to be the same unit, then use that unit and not "c", in fact, why substitute at all if there's only two lines using the c and s
var unit = unitA;
deltaX = unit._x-_root.enemy._x;
deltaY = unit._y-_root.enemy._y;
Copy link to clipboard
Copied
The script now looks like this but all i get is undifined.
var deltaX;
var deltaY;
var dist;
_root.onEnterFrame = function() {
var unitB = unitA;
deltaX = unitB._x-_root.enemy._x;
deltaY = unitB._y-_root.enemy._y;
// rounded distance
dist = Math.sqrt((deltaX*deltaX)+(deltaY*deltaY));
if(unitB.dist <= 100);
trace(shoot);
}
Copy link to clipboard
Copied
The code you show is incomplete at best. And you still do not have anything that loops thru the array to check each unit. The undefined could be pointing at your lack of defining a value for i, though it could also be that you haven't define a value for shoot. If shoot is not a variable and your intention is to display the word "shoot", then you need to use quotes
Copy link to clipboard
Copied
ok
thanks for ur help.
but im just going to rewright all my scripts again because im going to use a tile base system what will make it alot easier
ThankS!!!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more