Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

distance wont work...........is this script wright????

Participant ,
Aug 05, 2011 Aug 05, 2011

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);

}

.........................................................................................................

TOPICS
ActionScript
702
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 06, 2011 Aug 06, 2011

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

Translate
LEGEND ,
Aug 05, 2011 Aug 05, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 05, 2011 Aug 05, 2011

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 05, 2011 Aug 05, 2011

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 06, 2011 Aug 06, 2011

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 06, 2011 Aug 06, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 06, 2011 Aug 06, 2011
LATEST

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!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines