00:00
00:00
Newgrounds Background Image Theme

Mekatov just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Actionscript problem

1,541 Views | 3 Replies
New Topic Respond to this Topic

Actionscript problem 2005-05-26 13:58:14


I'm trying to make a flash RTS, but I have no clue how to get a selected unit to move/attack where I click. I thought about just dragging them and they attack automatically (kinda like Dungeon Keeper) but how would I make them attack enemies within a certain distance?
And how would I script the enemies? I need them to be able to wander around in an enclosed area and attack the player's units when they get within a certain distance. I also need to make sure that none of the units can walk through/be dropped on/stand on buildings and walls. I've got an HP script in mind but if anyone knows a good one and could post it I'd be grateful. THanks in advance to everyone who helps.

Response to Actionscript problem 2005-05-26 14:07:45


At 5/26/05 01:58 PM, LedxPighp wrote: stuff

No offence, I mean you're actually not that bad but still, don't even THINK of beginning a big game project without the required AS knowledge.


Sup, bitches :)

BBS Signature

Response to Actionscript problem 2005-05-26 14:12:29


Yeah, I guess I'll just work on smaller projects for a while. I was hoping to make something big, but that's beyond my ability at this moment.

Response to Actionscript problem 2005-05-26 14:24:25


Normally I'd say you're asking too much, but I'm feeling generous today. Plus, I'm working on something that adapts to this pretty easily

Create your Player MC
Inside it, have two circular MCs:
- one the size of your enemy, instance name 'centre'
- another say 200x200 pixels, which will be the area within which enemies will attack, instance name 'atkcircle'

Place your Player MC on stage, instance name it 'player'

Place your enemy MC on stage, add these actions:

onClipEvent(load){
spd=10; //Set enemy speed
}

onClipEvent(enterFrame){
if(this.hitTest(_parent.player.atkcircle)){
//rotate enemy
Xdiff=_parent.player._x-_x;
Ydiff=_parent.player._y-_y;
radAngle=Math.atan2(Ydiff,Xdiff);
_rotation=int((radAngle*360/(2*Math.PI))+90);
updateAfterEvent();

if(this.hitTest(_parent.player.centre)){
//Do attack
}else{
//Move
if(_rotation>180){
_y+=(spd*Math.cos(Math.PI/180*_rotation));
_x-=(spd*Math.sin(Math.PI/180*_rotation));
}else{
_y-=(spd*Math.cos(Math.PI/180*_rotation));
_x+=(spd*Math.sin(Math.PI/180*_rotation));
}
}
}
}

That won't deal with wandering or hitTesting boundaries, but it'll make the enemy chase you playerMC when it gets close.


- - Flash - Music - Images - -

BBS Signature