Be a Supporter!

AS:Ground Movement

  • 9,743 Views
  • 36 Replies
New Topic Respond to this Topic
Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
AS:Ground Movement Oct. 26th, 2005 @ 07:55 PM Reply

@5:/\/\@1|\|!!!!!!!11111
__________
This tutorial will teach you the basics to a game like Dad 'n Me...the movement style.

See what I'm talking about

Before you do anything,make a new movieclip.Make 2 frames.In the first frame,add a picture of your character standing.In the second frame,add a movieclip of your character running/walking.Also,add stop(); actions to each frame.Now keep reading.

Please don't be stupid.Add the code to the character MC :)

Start off by adding the variables.

onClipEvent (load) {
speed = 5;
speed2 = 3;
scale = _xscale;
}

We'll need to separate speed settings,one for the _x movement and one for the _y movement.The speeds need to be different,to give the game a somewhat realism effect thingy.Also,we'll use _xscale to change which way the character faces on each key press.

onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= speed2;
this.gotoAndStop(2);
}

'if':Here is the first ClipEvent.Using te 'if' function,we can create a Key.isDown function,so you can make the effects.When there is an 'if',there is a 'then'.Now,the first part of the script will be Key.UP.This doesn't really have to be UP,but it is right now.
'then':Now,your then will be movement and making your character walk.If you remember,the movieclip has 2 frames,standing and walking.You will be directed to frame 2 in the movie test when you press the buttons.Also,_y -= speed2; will make your character move upwards,and as you see,with him still facing one direction:left or right.The next parts of the script are exactly the same,just changed for different directions.

if (Key.isDown(Key.DOWN)) {
this._y += speed2;
this.gotoAndStop(2);
}

Same,just moves your character down with a 'plus'(+) sign.

if (Key.isDown(Key.LEFT)) {
this._x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}

You notice 2 things in this part of the script._y has changed to _x,and a new 'then' code has been added,the _xscale code so your character will turn.Please make sure your character starts off facing the right way :)

if (Key.isDown(Key.RIGHT)) {
this._x += speed;
this.gotoAndStop(2);
_xscale = +scale;
}
}
Same as above,just the 'minus'(-) sign has been changed to a 'plus'.

Now,to end this script,we need to use a new script to change the frame back to frame 1 and stop the walk/run animation.

onClipEvent (keyUp) {
this.gotoAndStop(1);
}

Notice how 'enterFrame' changed to 'keyUp'?Yah.

Here is the full code...

onClipEvent (load) {
speed = 5;
speed2 = 3;
scale = _xscale;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= speed2;
this.gotoAndStop(2);
}
if (Key.isDown(Key.DOWN)) {
this._y += speed2;
this.gotoAndStop(2);
}
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
this.gotoAndStop(2);
_xscale = +scale;
}
}
onClipEvent (keyUp) {
this.gotoAndStop(1);
}

Change the speed to whatever to make the speeds faster or whatever.Also,if you want to make the movement work with the keys 'W','S','A',and 'D',then just use the keycode example below...

65=A=LEFT
68=D=RIGHT
83=S=DOWN
87=W=UP

Do not make the code Key.65 or whatever,just use the number...example.

onClipEvent (enterFrame) {
if (Key.isDown(65)) {
this.gotoAndStop(4);
}
}

The end :)


wat
a compessor wil raise the volume while lowering the db - chronamut

RiftMaster
RiftMaster
  • Member since: Mar. 17, 2001
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS:Ground Movement Oct. 26th, 2005 @ 07:58 PM Reply

thats a good basic tutorial :)

hmm maybe I should make my quasi-3d depth-field engine open source :P


I put the "funk" in function()

ColdLogic
ColdLogic
  • Member since: Nov. 12, 2003
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to AS:Ground Movement Oct. 26th, 2005 @ 08:03 PM Reply

I'd like to see that

Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to AS:Ground Movement Oct. 26th, 2005 @ 08:04 PM Reply

Oh cool I got complimented by a website affiliate :)


wat
a compessor wil raise the volume while lowering the db - chronamut

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 12:39 PM Reply

You might also consider:

onClipEvent(enterFrame){
this.swapDepths(this._y+10);
}

On all your moving mc's

So your character can walk in front of and behind eachother depending on their _y value.

Heigher _y = heigher depth = in front of more stuff

I added a +10 just to boost it away from the 0 mark, going under 0 in depths results in loss of functionality such as removeMovieClip(), so its a good idea to keep them at depths >1, change the 10 according the the mc's height.

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 12:46 PM Reply

At 10/31/05 12:39 PM, T-H wrote: onClipEvent(enterFrame){
this.swapDepths(this._y+10);
}

That's a very good idea, I have to admit I would never think of it. It's just like _currentframe, a simple way to avoid big mess.


BBS Signature
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 12:59 PM Reply

Just a question: How can you know/trace an object's depth?
You can't do like, trace(this.swapDepths()), can you? =/


BBS Signature
IWantSomeCookies
IWantSomeCookies
  • Member since: Aug. 20, 2004
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 01:00 PM Reply

Thankyou T-H. I was just about to ask that question.

How, and where, would it be replaced and stuff?


"Actually, the server timed out trying to remove all your posts..."
-TomFulp

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 01:06 PM Reply

At 10/31/05 12:59 PM, -Toast- wrote: Just a question: How can you know/trace an object's depth?
You can't do like, trace(this.swapDepths()), can you? =/

Nevermind, I have an idea:

onClipEvent(enterFrame){
this.swapDepths(this._y+10);
myVar = this._y+10;
}

Then you can trace myVar and it will give you the depth.


BBS Signature
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 01:07 PM Reply

At 10/31/05 12:59 PM, -Toast- wrote: trace(this.swapDepths())

trace(this.getDepth());


BBS Signature
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 01:08 PM Reply

At 10/31/05 01:06 PM, -Toast- wrote: Then you can trace myVar and it will give you the depth.

trace(instance.getDepth());

Dude, look here.


Sup, bitches :)

BBS Signature
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 01:13 PM Reply

At 10/31/05 01:08 PM, -liam- wrote:
At 10/31/05 01:06 PM, -Toast- wrote: Then you can trace myVar and it will give you the depth.
trace(instance.getDepth());

Bleh, didn't know it existed :)

Dude, look here.

Bleh, didn't know it existed :)

Thanks Liam!


BBS Signature
T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 01:15 PM Reply

There is also a getInstanceAtDepth(number); (not sure if thats the exact syntax)

If you fancy targetting a mc at a certain depth to alter/remove it, never used that one before.

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 01:36 PM Reply

At 10/31/05 01:15 PM, T-H wrote: There is also a getInstanceAtDepth(number); (not sure if thats the exact syntax)

If you fancy targetting a mc at a certain depth to alter/remove it, never used that one before.

I have for one thing.. I made this:

function removeTarget(depth:Number):Void {
_root.removeMovieClip(_root.removeInstance
AtDepth(depth))
}

I made the MCs to be removed swap depths, then run that function just to see if it worked =)

it did.

Sup, bitches :)

BBS Signature
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 01:38 PM Reply

At 10/31/05 01:36 PM, -liam- wrote: _root.removeInstanceAtDepth

That was supposed to read "getInstanceAtDepth", har.. har.


Sup, bitches :)

BBS Signature
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Ground Movement Oct. 31st, 2005 @ 01:38 PM Reply

:D


BBS Signature
Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to AS:Ground Movement Nov. 2nd, 2005 @ 09:10 PM Reply

At 10/31/05 01:38 PM, -Toast- wrote:
D

When you go behind the first-left building,then go up to touch the one above it,you go behind it.


wat
a compessor wil raise the volume while lowering the db - chronamut

deadpool15
deadpool15
  • Member since: Jul. 26, 2005
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS:Ground Movement Jul. 24th, 2006 @ 04:33 PM Reply

hi, i really suck at AS and I was wondering if you could help me out by adding a 'jump' button but not changing the action script ....please?

deadpool15
deadpool15
  • Member since: Jul. 26, 2005
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS:Ground Movement Jul. 25th, 2006 @ 07:29 AM Reply

pretty please?...

Delta66
Delta66
  • Member since: Aug. 9, 2006
  • Offline.
Forum Stats
Member
Level 11
Artist
Response to AS:Ground Movement Nov. 8th, 2006 @ 06:37 PM Reply

How do you make a wall?You know I want to know how to make a simple wall.Please help?


hello

Sinistermuffin
Sinistermuffin
  • Member since: Sep. 16, 2006
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS:Ground Movement Jan. 19th, 2007 @ 05:36 PM Reply

At 11/8/06 06:37 PM, Tek-dude wrote: How do you make a wall?You know I want to know how to make a simple wall.Please help?

YES that would help A LOT, i'd be PERFECT for the game I'm making

; somebody do it PLZ

PLEASE
)
JackSmack
JackSmack
  • Member since: Nov. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Game Developer
Response to AS:Ground Movement Mar. 9th, 2007 @ 07:01 PM Reply

The only problem I see is you have the _xscale flip on key press so if the toon is facing right and you hit the right button he turns left.

if you have the scale for left and right set to variables and just call the varable rather than adding the scale to it it would work a little smoother but good over all.

I'll tinker with the code a bit and see what I can come up with.


Visit JackSmack.com and submit your Flash Games!

BBS Signature
JackSmack
JackSmack
  • Member since: Nov. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Game Developer
Response to AS:Ground Movement Mar. 9th, 2007 @ 07:03 PM Reply

Scratch that it was just a graphic glitch on my end.


Visit JackSmack.com and submit your Flash Games!

BBS Signature
Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to AS:Ground Movement Mar. 9th, 2007 @ 07:23 PM Reply

Shit this thread is old


wat
a compessor wil raise the volume while lowering the db - chronamut

Penboy
Penboy
  • Member since: Jun. 17, 2006
  • Offline.
Forum Stats
Member
Level 17
Artist
Response to AS:Ground Movement Mar. 9th, 2007 @ 07:53 PM Reply

That was a great help.

JackSmack
JackSmack
  • Member since: Nov. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Game Developer
Response to AS:Ground Movement Apr. 3rd, 2007 @ 09:04 PM Reply

actually I did find one problem that I can't figure out.

If the user is walking diagonaly with two keys down and releases them both at the exact same time the walk cycle continues to play.

is there a quick work around for that?


Visit JackSmack.com and submit your Flash Games!

BBS Signature
SNARE
SNARE
  • Member since: May. 14, 2004
  • Offline.
Forum Stats
Member
Level 25
Blank Slate
Response to AS:Ground Movement Apr. 7th, 2007 @ 05:42 PM Reply

At 4/3/07 09:04 PM, JackSmack wrote: actually I did find one problem that I can't figure out.

If the user is walking diagonaly with two keys down and releases them both at the exact same time the walk cycle continues to play.

is there a quick work around for that?

PLEASEPLEASE someone answer this

jozojozojozo
jozojozojozo
  • Member since: Sep. 5, 2005
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS:Ground Movement Apr. 12th, 2007 @ 02:40 PM Reply

Hey, would it be possable to have a download link for the imageshack file?
Just curious =]
Ty btw<3


LOL @ this review
Great i love it. A must if you love blowin peoples heads off.
For game http://www.newgrounds.com/portal/vi ew/283047

jozojozojozo
jozojozojozo
  • Member since: Sep. 5, 2005
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS:Ground Movement Apr. 12th, 2007 @ 07:16 PM Reply

Mmm.. Dunno why i was asking for a download o_O
All we need now is a tutorial for shooting and walls =]]]


LOL @ this review
Great i love it. A must if you love blowin peoples heads off.
For game http://www.newgrounds.com/portal/vi ew/283047

Mad-Nimmy
Mad-Nimmy
  • Member since: May. 18, 2006
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to AS:Ground Movement Jul. 27th, 2007 @ 05:37 PM Reply

At 10/26/05 07:55 PM, Thomas wrote: Start off by adding the variables.

onClipEvent (load) {
speed = 5;
speed2 = 3;
scale = _xscale;
}

What do you mean adding the variables?....Where do i add that script? on the movie clip? on the frame of the movie clip?

I didn't really understand what you meant..

(I'm a huge noob..)