ForumsProgramming ForumHelp me please (actionscript 2)

14 4897
jimmy155
offline
jimmy155
39 posts
Nomad

http://www.newgrounds.com/dump/item/27db 991ca239b4fe2a76c7690082d861
see the problem? the enemy won't move or attack, how do i make him move and attack the player? actionscript 2, please help.

i want it to be a fighting game, and that the enemy follows the player and attack( like in rage 3)
the instance name of the enemy is enemy
and the instance name of the player is hero

  • 14 Replies
jimmy155
offline
jimmy155
39 posts
Nomad

[url=http://www.newgrounds.com/dump/item/27db991ca239b4fe2a76c7690082d861]

DapwnageG
offline
DapwnageG
205 posts
Nomad

To make him move.

if(_root.Hero._x > this._x){
this._x += 1;
}
if(_root.Hero._x < this._x){
this._x -= 1;
}
Just mix that with the movement code the hero uses and it will work.

To make him attack.

if(this.hitTest(_root.Hero)){
this.gotoAndPlay("attack&quot;
_root.Health -= 1;
}

You are probably going to need to change up the code a bit to add other variables and such. There might be a few errors too.

DapwnageG
offline
DapwnageG
205 posts
Nomad

Just mix that with the movement code the hero uses and it will work.


Ignore that sentence
jimmy155
offline
jimmy155
39 posts
Nomad

how do i make it so when he walks he goes to a certain frame?( i want to animate the walking)

DapwnageG
offline
DapwnageG
205 posts
Nomad

Make another movie clip of him walking, and put it in the actual enemy movieclip on the second frame, and change his code to this:

if(_root.Hero._x > this._x){
this._x += 1;
this.gotoAndStop(2);
}
else if(_root.Hero._x < this._x){
this._x -= 1;
this.gotoAndStop(2);
}else{
this.gotoAndStop(1);
}

It should work then.

jimmy155
offline
jimmy155
39 posts
Nomad

sorry for my total noobyness, but could you please post the full code with the clipevent handler?

DapwnageG
offline
DapwnageG
205 posts
Nomad

onClipEvent(load){
attack = false;
}
onClipEvent(enterFrame){
if(_root.Hero._x > this._x){
this._x += 1;
this.gotoAndStop(2);
}
else if(_root.Hero._x < this._x){
this._x -= 1;
this.gotoAndStop(2);
}else{
this.gotoAndStop(1);
}
if(this.hitTest(_root.Hero)){
this.gotoAndPlay("attack&quot;
_root.Health -= 1;
}
}

jimmy155
offline
jimmy155
39 posts
Nomad

does not work, any other ideas?

gone3d
offline
gone3d
17 posts
Nomad

you want the enemy to follow the hero, so make the enemy move towards the hero (like the above code is trying to do), but you're not changing the enemy._x value.

trace this out and see what they are when you run it

set the key controls to move the hero left and right so you can test to see if the enemy follows.

good luck,

D

jimmy155
offline
jimmy155
39 posts
Nomad

as i said, i'm a noob, so can't someone just post the code?
btw the "hero" instance is not capitalized

jimmy155
offline
jimmy155
39 posts
Nomad

http://www.newgrounds.com/dump/item/27db991ca239b4fe2a76c7690082d861

halogunner
offline
halogunner
807 posts
Nomad

kind of off topic but my name is jimmy to only i am cooler

jimmy155
offline
jimmy155
39 posts
Nomad

HEEELP

jimmy155
offline
jimmy155
39 posts
Nomad

anyone?

Showing 1-14 of 14