Be a Supporter!

action script moving?

  • 417 Views
  • 26 Replies
New Topic Respond to this Topic
up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
action script moving? 2010-04-30 18:31:28 Reply

I have this game where a bad guy has to move, how can I make the bad guy move side to side with as2?


Bipolar Smiley: (:(

BBS Signature
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to action script moving? 2010-04-30 18:42:53 Reply

by using the search bar on the bottom of this page ;)

this is a frequently asked question, I'm sure you'll find something,

you basically do the same thing as if you moved him in flash "by hand", you change the x and y coordinates

up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-04-30 18:46:51 Reply

what should I search?


Bipolar Smiley: (:(

BBS Signature
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to action script moving? 2010-04-30 18:53:49 Reply

At 4/30/10 06:46 PM, up-a-notch wrote: what should I search?

did you actualyl even read the "New to Flash? read this" topic?
If not you better do that now, you can find your answer there.

up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-04-30 19:27:09 Reply

this is what I came up with

onClipEvent (load) {
_root.Moby._x += 10;
}


Bipolar Smiley: (:(

BBS Signature
up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-04-30 21:16:27 Reply

bump


Bipolar Smiley: (:(

BBS Signature
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to action script moving? 2010-05-01 03:18:23 Reply

At 4/30/10 07:27 PM, up-a-notch wrote: onClipEvent (load) {
_root.Moby._x += 10;
}

well, almost. Where do you have the code from?
Do not code on the movieclip itself, code on the main timeline.
This has all been said and done before way toooo many times.

up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-05-01 09:26:18 Reply

i made the code


Bipolar Smiley: (:(

BBS Signature
up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-05-01 10:47:26 Reply

i put this on the frame: _root.Moby._x += 10;


Bipolar Smiley: (:(

BBS Signature
Neo-13
Neo-13
  • Member since: Jun. 9, 2007
  • Offline.
Forum Stats
Member
Level 23
Programmer
Response to action script moving? 2010-05-01 11:13:27 Reply

At 5/1/10 10:47 AM, up-a-notch wrote: i put this on the frame: _root.Moby._x += 10;

That will make it move 10 pixels to the right at the start of the movie. You need to call it inside this:

function onEnterFrame()
{
   // movement code
}

That function will be called every frame, and you should see your MovieClip moving by 10 pixels every frame (it would stay on screen for long).


BBS Signature
Neo-13
Neo-13
  • Member since: Jun. 9, 2007
  • Offline.
Forum Stats
Member
Level 23
Programmer
Response to action script moving? 2010-05-01 11:14:30 Reply

At 5/1/10 11:13 AM, Neo-13 wrote: (it would stay on screen for long).

Typo, should be:

(it won't stay on screen for long).


BBS Signature
up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-05-01 12:16:09 Reply

i know when it hits an invisable movie clip it will go the other way and viceversa


Bipolar Smiley: (:(

BBS Signature
Neo-13
Neo-13
  • Member since: Jun. 9, 2007
  • Offline.
Forum Stats
Member
Level 23
Programmer
Response to action script moving? 2010-05-01 12:24:52 Reply

At 5/1/10 12:16 PM, up-a-notch wrote: i know when it hits an invisable movie clip it will go the other way and viceversa

I was just explaining what the code was actually doing, and then pointing out that it will move quite fast.


BBS Signature
up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-05-01 12:45:35 Reply

oh then is 1 pixel good?


Bipolar Smiley: (:(

BBS Signature
up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-05-01 12:56:24 Reply

whats wrong with this?

function onEnterFrame() {

_root.Moby._x += 4;
}
function onEnterFrame() {
if (this.hitTest(_root.wall1)) {
_root.Moby._x -= 4;
}

}
function onEnterFrame() {
if (this.hitTest(_root.wall2)) {
_root.Moby._x += 4;
}
}


Bipolar Smiley: (:(

BBS Signature
Neo-13
Neo-13
  • Member since: Jun. 9, 2007
  • Offline.
Forum Stats
Member
Level 23
Programmer
Response to action script moving? 2010-05-01 13:23:23 Reply

1 pixel might be 'good', but obviously it depends - 10 might still be what you want.

As for your code, why are you using 'this'? Think about how that doesn't make sense.

Remember that you are testing for a collision between MC1 and MC2... now think about it.


BBS Signature
Neo-13
Neo-13
  • Member since: Jun. 9, 2007
  • Offline.
Forum Stats
Member
Level 23
Programmer
Response to action script moving? 2010-05-01 13:24:58 Reply

At 5/1/10 01:23 PM, Neo-13 wrote: 1 pixel might be 'good', but obviously it depends - 10 might still be what you want.

As for your code, why are you using 'this'? Think about how that doesn't make sense.

Remember that you are testing for a collision between MC1 and MC2... now think about it.

Forgot to mention, put it all in one enterFrame function not three separate ones.


BBS Signature
up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-05-01 13:31:47 Reply

but this has errors

function onEnterFrame() {

_root.Moby._x += 4;
}
function onEnterFrame() {
if (_root.Moby.hitTest(_root.wall1)) {
_root.Moby._x -= 4;
}

function onEnterFrame() {
if (_root.Moby.hitTest(_root.wall2)) {
_root.Moby._x += 4;
}
}


Bipolar Smiley: (:(

BBS Signature
Callum123456
Callum123456
  • Member since: Mar. 7, 2009
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to action script moving? 2010-05-01 13:38:35 Reply

At 5/1/10 01:31 PM, up-a-notch wrote: but this has errors

Always post the exact error.

Neo-13
Neo-13
  • Member since: Jun. 9, 2007
  • Offline.
Forum Stats
Member
Level 23
Programmer
Response to action script moving? 2010-05-01 13:39:00 Reply

At 5/1/10 01:31 PM, up-a-notch wrote: but this has errors

function onEnterFrame() {

_root.Moby._x += 4;
}
function onEnterFrame() {
if (_root.Moby.hitTest(_root.wall1)) {
_root.Moby._x -= 4;
}

function onEnterFrame() {
if (_root.Moby.hitTest(_root.wall2)) {
_root.Moby._x += 4;
}
}

If you have errors, EXPLAIN WHAT THEY ACTUALLY ARE. OK?
Secondly, as I said, get rid of the extra enterFrames, and you have a missing '}' as well. Listen to advice and don't use (copied?) code you don't understand.


BBS Signature
up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-05-01 13:56:16 Reply

it was not copied I just need help cause I am not an expert!


Bipolar Smiley: (:(

BBS Signature
Callum123456
Callum123456
  • Member since: Mar. 7, 2009
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to action script moving? 2010-05-01 18:26:21 Reply

At 5/1/10 01:56 PM, up-a-notch wrote: it was not copied I just need help cause I am not an expert!

You still haven't posted the errors, how is anybody meant to help you?

CyanSandwich
CyanSandwich
  • Member since: Aug. 14, 2009
  • Offline.
Forum Stats
Member
Level 42
Programmer
Response to action script moving? 2010-05-01 18:53:58 Reply

you need 1 more "}" at the end


BBS Signature
CyanSandwich
CyanSandwich
  • Member since: Aug. 14, 2009
  • Offline.
Forum Stats
Member
Level 42
Programmer
Response to action script moving? 2010-05-01 19:00:34 Reply

actually no not at the end. let me recode it for you.

function onEnterFrame(){
moby._x +=4;
if(moby.hittest(wall1)){
moby._x -=4;
}
if(moby.hitTest(wall2)){
moby._x +=4;
}
}

you dont need to use _root when you code on the main timeline


BBS Signature
up-a-notch
up-a-notch
  • Member since: Sep. 29, 2009
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-05-02 13:51:41 Reply

He does not go the other way when he hits the wall


Bipolar Smiley: (:(

BBS Signature
Neo-13
Neo-13
  • Member since: Jun. 9, 2007
  • Offline.
Forum Stats
Member
Level 23
Programmer
Response to action script moving? 2010-05-02 13:56:31 Reply

At 5/2/10 01:51 PM, up-a-notch wrote: He does not go the other way when he hits the wall

OK.


BBS Signature
Fiziks
Fiziks
  • Member since: Nov. 23, 2008
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to action script moving? 2010-05-02 15:06:46 Reply

AS: Main

I know there's an AI scripting tutorial in there somewhere, as well as every other useful effect you could possibly need. Well, almost. I recommend book marking it if you're trying to learn AS.


[Steam User + CS:S Modder] This. | SLENDERMAN. RUN FOR YOUR FUCKING LIFE.

BBS Signature