Posted By
|
Message
|
c-jayf
Registered 06/07/2003
Points 274
|
19th March, 2005 at 23:31:47 -
I need help thinking of a way to make an enemy walk towards you... (look at you, and try to bump into you). I can't figure out a way.
I hate witty signatures.
|
Radix hot for teacher
Registered 01/10/2003
Points 3139
|
19th March, 2005 at 23:53:42 -
I'm a ssuming you mean an enemy that stands there, and when it spots you runs towards your character.
One method:
Enemy flag 0: 1=left, 0=right
Enemy value A: persistance
Enemy value B: distance traversed
When your enemy spots the player, which can be done with invisble bullets fired to establish line-of-sight, value A is set to something arbitrary, maybe 50 or so. It is repeatedly reset to 50 as long as the enemy can still see the player (again using invisible bullets). If a left-firing bullet detects the player, flag 0 is set to 1. If a right-firing bullet collides, 0 is set to 0.
You also need invisible blocks that determine what can stop the enemy moving, like a wall or the edge of a platform.
Enemy value A > 0
+Enemy not overlapping invisible block
+Enemy flag 0 = 1
--Enemy: set x to X(Enemy) -1
--Enemy: subtract 1 from alterable value A
--Enemy: add 1 to alterable value B
That'll have it run left. Do something similar to move right.
Enemy is overlapping invisible block
--Enemy: Set value A to 0
Alterable value A of Enemy = 0
+Alterable value B of enemy > 0
+Enemy flag 0 = 1
--Enemy: set x to X(Enemy) + 1
--Enemy: subtract 1 from alterable value B
That'll return it to its original position if it was facing left to begin with. Do something similar for the right.
Also, it might be better to make right-movement subtract from B, and then subtract negatives for its return to original position, that way if its direction is changed while A>0 it'll always return to the same spot. I'd write that in to the above events, but I don't feel like it.
n/a
|
|
|