How do I make an enemy pace and stop?

Get help using Construct 2

Post » Mon Oct 10, 2016 2:27 am

got an enemy with a platform behavior and i want him to jump at random intervals (which works fine and was easy to get right) and also to walk forward or backwards for about half a second at different, also random intervals. thing is, setting him to move "every x seconds" will only input that control for one frame. any thoughts on how i can sustain that movement long enough to matter, but also have him stop in between and not just go from left to right?
B
15
S
8
G
2
Posts: 10
Reputation: 2,434

Post » Mon Oct 10, 2016 7:54 am

You can simulate left/right whilst a boolean is enabled then switch it off, or you could make use of rexrainbow moveto plugin.
B
46
S
16
G
74
Posts: 2,088
Reputation: 44,185

Post » Mon Oct 10, 2016 11:06 am

Tigeri102 wrote:got an enemy with a platform behavior and i want him to jump at random intervals (which works fine and was easy to get right) and also to walk forward or backwards for about half a second at different, also random intervals. thing is, setting him to move "every x seconds" will only input that control for one frame. any thoughts on how i can sustain that movement long enough to matter, but also have him stop in between and not just go from left to right?


Ok from your post I am assuming you know how to get the enemy moving left and right but you want him to stop for a moment before turning around.

Ok basically let say you have an invisible box the your enemy hits to make him move back and forth.
Collision , with invisiblebox = accelleration=0
wait(2.0)
accelleration=1000
moveleft=1
moveright=0
Check out my awesome Android Game releases https://play.google.com/store/apps/deve ... ames&hl=en
B
38
S
18
G
24
Posts: 681
Reputation: 16,613

Post » Mon Oct 10, 2016 5:35 pm

I would recommend learning how to create a "state-machine" (I believe that is what they are called).

So you would have an instance variable called "state" and depending on what that is corresponds with what he does. Timer behavior would be needed to go along with this.

Example:
If state = "right" then simulate right
If state = "left" then simulate left
If state = "idle" then idle animation

On Timer
-state = "left" or "right" then state = "idle"
-state = "idle"
--Choose(0, 1) > 0 then state = "left"
--Else state = "right"
Restart Timer

This is the basics, if you want more states then just map out the order that they should move through states. For example one I've done for shooting zombies is idle -> aim -> fire -> recoil -> recover(just a pause) -> idle ... but from idle a different chain can occur such as move, reload, etc.

Jumping at random intervals can be done as a state or separately with a timer. When setting state to left or right start the state timer and also a jump timer (can set to random time). On timer simulate jump.


Edit: definitely add the "Else" where applicable in above commands
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Mon Oct 10, 2016 8:30 pm

badmoodtaylor wrote:I would recommend learning how to create a "state-machine" (I believe that is what they are called).

So you would have an instance variable called "state" and depending on what that is corresponds with what he does. Timer behavior would be needed to go along with this.

Example:
If state = "right" then simulate right
If state = "left" then simulate left
If state = "idle" then idle animation

On Timer
-state = "left" or "right" then state = "idle"
-state = "idle"
--Choose(0, 1) > 0 then state = "left"
--Else state = "right"
Restart Timer

This is the basics, if you want more states then just map out the order that they should move through states. For example one I've done for shooting zombies is idle -> aim -> fire -> recoil -> recover(just a pause) -> idle ... but from idle a different chain can occur such as move, reload, etc.

Jumping at random intervals can be done as a state or separately with a timer. When setting state to left or right start the state timer and also a jump timer (can set to random time). On timer simulate jump.


Edit: definitely add the "Else" where applicable in above commands


that sounds like the best way to do it, thanks man! pretty much everything i was coming up with last night would've had more regulated movement that i'd like
B
15
S
8
G
2
Posts: 10
Reputation: 2,434

Post » Mon Oct 10, 2016 8:42 pm

You are welcome!

...and I just realize instead of choose(0, 1)... you can just set state = choose("left", "right")

Let me know if you have any questions
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925


Return to How do I....?

Who is online

Users browsing this forum: unxcellent, Yahoo [Bot] and 10 guests