Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: ActionScript Help Please?

(167 views • 16 replies)

This topic is 1 page long.

<< < > >>
Crying

thodmick

Reply To Post Reply & Quote

Posted at: 5/14/08 05:24 PM

thodmick LIGHT LEVEL 02

Sign-Up: 10/29/06

Posts: 88

I need help.
How do I make it so that if this movie clip is closer than 60 from the character it will move away?

Right now it just moves closer if it's further than 60. But I want it to always walk towards 60 kinda.

onClipEvent (enterFrame) {
if (_root.player._x>_x + 60) {
_x += 5
gotoAndStop(2);
\\\ moving clip
} else if (_root.player._x<_x - 60){
_x -= 5;
gotoAndStop(2);
\\\ moving clip
} else {
gotoAndStop(1);
\\\ standing clip
}
}


None

DJMAX

Reply To Post Reply & Quote

Posted at: 5/14/08 05:29 PM

DJMAX LIGHT LEVEL 05

Sign-Up: 03/11/08

Posts: 191

try inversing your if/then/else commands.

!DJ MAX!
Ive gotten great feedback and im quite pleased with it myself! v.3 of my site! GO CHECK IT OUT! ITS AMAZING!

BBS Signature

None

thodmick

Reply To Post Reply & Quote

Posted at: 5/14/08 05:36 PM

thodmick LIGHT LEVEL 02

Sign-Up: 10/29/06

Posts: 88

At 5/14/08 05:29 PM, DJMAX wrote: try inversing your if/then/else commands.

That wont work. =(

already tried it.


None

thodmick

Reply To Post Reply & Quote

Posted at: 5/14/08 06:06 PM

thodmick LIGHT LEVEL 02

Sign-Up: 10/29/06

Posts: 88

Please, I really need help and I want to learn.


Crying

thodmick

Reply To Post Reply & Quote

Posted at: 5/14/08 06:46 PM

thodmick LIGHT LEVEL 02

Sign-Up: 10/29/06

Posts: 88

Plz help me ='(


None

TrillingBird

Reply To Post Reply & Quote

Posted at: 5/14/08 07:02 PM

TrillingBird LIGHT LEVEL 03

Sign-Up: 04/11/08

Posts: 291

At 5/14/08 06:46 PM, thodmick wrote: Plz help me ='(

change ur positive to a negative maybe


None

dragonjet

Reply To Post Reply & Quote

Posted at: 5/14/08 08:59 PM

dragonjet EVIL LEVEL 19

Sign-Up: 12/02/05

Posts: 543

is this just horizontal?
or 60 units around?


None

thodmick

Reply To Post Reply & Quote

Posted at: 5/14/08 10:27 PM

thodmick LIGHT LEVEL 02

Sign-Up: 10/29/06

Posts: 88

At 5/14/08 08:59 PM, dragonjet wrote: is this just horizontal?
or 60 units around?

Just horizontal.


None

oreidoouro

Reply To Post Reply & Quote

Posted at: 5/15/08 01:26 AM

oreidoouro NEUTRAL LEVEL 01

Sign-Up: 05/14/08

Posts: 9

where is the clip going to placed in relation to the charactor? randomly along the x axis? you might need to set some variables to reverse the push pull effect if its on the otherside of the charactor


None

OneWhoListens

Reply To Post Reply & Quote

Posted at: 5/15/08 01:59 AM

OneWhoListens LIGHT LEVEL 19

Sign-Up: 08/23/06

Posts: 1,267

The problem you have is that your two desires contradict each other. On the one hand, you want the object to move closer to the character while it is more than 60 points away. On the other hand, you want it to start moving away when it is closer than 60. There is an inherent problem here. If it reaches, say, a distance of 59 points, and starts moving away, then it will soon reach 60 points again, whereupon it's commands will tell it to start moving closer again. Essentially, it gets stuck. Only if the character moves further away will it begin approaching again, as the character is now more than 60 points away from it. If you move it too close, it will not be able to move closer, and will stop.
See the problem?
As for a solution, you will need to work with some variables, I'm thinking, and timer-like code that forces the object to move a certain distance/time before reconsidering the distance from it's target to itself. I'm sure there are also other ways, and there are also many possible variations in this one, however, this particular one was what popped into mind atm.


None

thodmick

Reply To Post Reply & Quote

Posted at: 5/15/08 04:26 PM

thodmick LIGHT LEVEL 02

Sign-Up: 10/29/06

Posts: 88

So, any help?


None

Cojones893

Reply To Post Reply & Quote

Posted at: 5/15/08 04:33 PM

Cojones893 EVIL LEVEL 21

Sign-Up: 03/09/03

Posts: 2,221

At 5/15/08 04:26 PM, thodmick wrote: So, any help?

OneWhoListens gave you your answer. Read his post and rewrite your code.


Shouting

thodmick

Reply To Post Reply & Quote

Posted at: 5/15/08 04:48 PM

thodmick LIGHT LEVEL 02

Sign-Up: 10/29/06

Posts: 88

At 5/15/08 04:33 PM, Cojones893 wrote:
At 5/15/08 04:26 PM, thodmick wrote: So, any help?
OneWhoListens gave you your answer. Read his post and rewrite your code.

I have no Idea how to do that =O


None

thodmick

Reply To Post Reply & Quote

Posted at: 5/15/08 09:19 PM

thodmick LIGHT LEVEL 02

Sign-Up: 10/29/06

Posts: 88

How!!!?


None

Zheg

Reply To Post Reply & Quote

Posted at: 5/15/08 10:31 PM

Zheg EVIL LEVEL 05

Sign-Up: 03/05/06

Posts: 122

onClipEvent (enterFrame) {
if (_root.player._x +60 >_root.enemy._x ) {
_root.enemy._x+= 5
gotoAndStop(2);
\\\ moving clip
} else if (_root.player._x -60 >_root.enemy._x ) {
_root.enemy._x-= 5;
gotoAndStop(2);
\\\ moving clip
} else {
gotoAndStop(1);
\\\ standing clip
}
}


Happy

dragonjet

Reply To Post Reply & Quote

Posted at: 5/16/08 12:16 AM

dragonjet EVIL LEVEL 19

Sign-Up: 12/02/05

Posts: 543

onClipEvent (enterFrame) {
     moving=false;

     if (Math.abs(_root.player._x-_x) > 63) {
          if(_root.player._x>_x){ _x+=5; }else _x-=5;
          _x += 5
          gotoAndStop(2);
          moving=true;
     }

     if (Math.abs(_root.player._x-_x) < 57){
          if(_root.player._x>_x){ _x-=5; }else _x+=5;
          gotoAndStop(2);
          moving=true;
     }

     if(moving){
          // moving clip
     } else {
          // standing clip
     }
}

None

dragonjet

Reply To Post Reply & Quote

Posted at: 5/16/08 12:17 AM

dragonjet EVIL LEVEL 19

Sign-Up: 12/02/05

Posts: 543

damn i didn't notice an extra code which should not be there,
here is the correct one...

onClipEvent (enterFrame) {
     moving=false;

     if (Math.abs(_root.player._x-_x) > 63) {
          if(_root.player._x>_x){ _x+=5; }else _x-=5;
          gotoAndStop(2);
          moving=true;
     }

     if (Math.abs(_root.player._x-_x) < 57){
          if(_root.player._x>_x){ _x-=5; }else _x+=5;
          gotoAndStop(2);
          moving=true;
     }

     if(moving){
          // moving clip
     } else {
          // standing clip
     }
}

All times are Eastern Daylight Time (GMT -4) | Current Time: 10:36 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!