Community

Help me please (actionscript 2)

Posted Aug 31, '10 at 7:35pm

jimmy155

jimmy155

39 posts

Iron - Serf

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

Posted Aug 31, '10 at 7:44pm

jimmy155

jimmy155

39 posts

Iron - Serf

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

 

Posted Aug 31, '10 at 9:01pm

DapwnageG

DapwnageG

94 posts

Wood - Squire

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");
_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.

 

Posted Aug 31, '10 at 9:03pm

DapwnageG

DapwnageG

94 posts

Wood - Squire

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

Ignore that sentence :D

 

Posted Aug 31, '10 at 9:21pm

jimmy155

jimmy155

39 posts

Iron - Serf

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

 

Posted Aug 31, '10 at 9:25pm

DapwnageG

DapwnageG

94 posts

Wood - Squire

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.

 

Posted Aug 31, '10 at 9:28pm

jimmy155

jimmy155

39 posts

Iron - Serf

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

 

Posted Aug 31, '10 at 9:36pm

DapwnageG

DapwnageG

94 posts

Wood - Squire

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");
  _root.Health -= 1;
}
}

 

Posted Sep 2, '10 at 2:28pm

jimmy155

jimmy155

39 posts

Iron - Serf

does not work, any other ideas?

 

Posted Sep 2, '10 at 4:24pm

gone3d

gone3d

17 posts

Wood - Squire

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

 

Posted Sep 2, '10 at 5:14pm

jimmy155

jimmy155

39 posts

Iron - Serf

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

 
Reply to Help me please (actionscript 2)

You must be logged in to post a reply!