Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Follow Enemy?

(95 views • 11 replies)

This topic is 1 page long.

<< < > >>
Questioning

SuperSpeedo

Reply To Post Reply & Quote

Posted at: 7/2/08 01:51 AM

SuperSpeedo FAB LEVEL 03

Sign-Up: 06/12/08

Posts: 40

how i can do thet?
to do thet- the enemy will follows after the player?
the name of the enemy is 'e' and the player name is 'player'
In AS2
beacuse i do thet thing:
:onClipEvent(enterFrame){
_root.e._x = _root.player._x ;
_root.e._xscale = _root.player._x;
}

the scale isn't so metter...
but after i do thet the enemy is stick to the player and it doesn't looks like he is go to the player - when you start he just on you...
plz help me...


Sad

SuperSpeedo

Reply To Post Reply & Quote

Posted at: 7/2/08 02:11 AM

SuperSpeedo FAB LEVEL 03

Sign-Up: 06/12/08

Posts: 40

plz help me...


None

Coaly

Reply To Post Reply & Quote

Posted at: 7/2/08 02:27 AM

Coaly FAB LEVEL 20

Sign-Up: 08/11/04

Posts: 2,582

You wont usually get an answer within 20 minutes at 2am...it's kinda slow. Anyway I'm not sure why you want to alter the xscale, but if you set the enemies _x position to the player's _x position it's obviously going to be at the players _x position... What you want to do is if the enemies _x position is greater than the player's subtract from the position, and if it's less than the player's, add to the position.

if(e._x < player._x){
  e._x += 1;
}else if(e._x>player._x){
  e._x -= 1;
}
if(Math.abs(e._x-player._x) < 1){
  e._x = player._x
}

The bottom if statement checks if the distance between the enemy and player is less than 1, so the enemy doesn't jitter.

Error

BBS Signature

Misunderstood

SuperSpeedo

Reply To Post Reply & Quote

Posted at: 7/2/08 02:55 AM

SuperSpeedo FAB LEVEL 03

Sign-Up: 06/12/08

Posts: 40

its not working good....
he walk to the player and if the player pass him he still going to the same place and not to the player...


None

Coaly

Reply To Post Reply & Quote

Posted at: 7/2/08 02:58 AM

Coaly FAB LEVEL 20

Sign-Up: 08/11/04

Posts: 2,582

At 7/2/08 02:55 AM, SuperSpeedo wrote: its not working good....
he walk to the player and if the player pass him he still going to the same place and not to the player...

Maybe you don't have the instance names correct, or the path, depending on where the code is you may need to use _root.

Error

BBS Signature

None

SuperSpeedo

Reply To Post Reply & Quote

Posted at: 7/2/08 03:02 AM

SuperSpeedo FAB LEVEL 03

Sign-Up: 06/12/08

Posts: 40

i used _root....and its doesn't work XD(its not make any sensse- if(e.blablabla){


None

Coaly

Reply To Post Reply & Quote

Posted at: 7/2/08 03:23 AM

Coaly FAB LEVEL 20

Sign-Up: 08/11/04

Posts: 2,582

At 7/2/08 03:02 AM, SuperSpeedo wrote: i used _root....and its doesn't work XD(its not make any sensse- if(e.blablabla){

Well _x is a property of a movieclip that is it's x position, and greater than and less than (>,<) are used for comparison. So when the enemies x is is greater than the players x, you subtract one from the enemies x to move it closer to the player. It's very simple, you need to exert some effort if you want to learn or know how to do anything... saying that nothing makes sense doesn't help, because most of it really really should make sense.

Error

BBS Signature

None

The-Swain

Reply To Post Reply & Quote

Posted at: 7/2/08 03:47 AM

The-Swain LIGHT LEVEL 07

Sign-Up: 09/16/05

Posts: 351

I know this doesn't help you very much or at all, but when learning to code in any language, it's better to figure out the concepts first and then learn the code that will help you to accomplish it. Asking people how to help your game to function will be a long but fruitless task.

For example, in this case think of it conceptually. Player position has an X position, and the enemy has an X position. The enemy needs to make their X position get closer to the player's X position over time. If you can picture the math and the concept, you'll be fine. To me it sounds like you're asking for help both with concept and with the code itself, and that's no good for anyone.

BBS Signature

Expressionless

SuperSpeedo

Reply To Post Reply & Quote

Posted at: 7/2/08 05:00 AM

SuperSpeedo FAB LEVEL 03

Sign-Up: 06/12/08

Posts: 40

listen the enemy just going _x +=1 all the time and its kinda ignore the script...


Elated

SuperSpeedo

Reply To Post Reply & Quote

Posted at: 7/2/08 05:05 AM

SuperSpeedo FAB LEVEL 03

Sign-Up: 06/12/08

Posts: 40

i do something in the script and now its work!
and did you know how to make him look at the enemy?- like _xscale thet looking to the enemy?


Misunderstood

BloodSucker150

Reply To Post Reply & Quote

Posted at: 7/2/08 06:06 AM

BloodSucker150 LIGHT LEVEL 11

Sign-Up: 03/20/08

Posts: 495

plz help me with the _xscale...


Goofy

BloodSucker150

Reply To Post Reply & Quote

Posted at: 7/2/08 06:18 AM

BloodSucker150 LIGHT LEVEL 11

Sign-Up: 03/20/08

Posts: 495

At 7/2/08 06:06 AM, BloodSucker150 wrote: plz help me with the _xscale...

woops sorry wrong place XD


All times are Eastern Daylight Time (GMT -4) | Current Time: 05:53 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!