How do I make a stalking enemy (on the x axis)?

Just started using Construct 2? Post your questions here

Post » Wed Apr 02, 2014 7:16 pm

Hi guys, I started playing around with Construct 2 the other night and it was really easy setting up basic things. My first questionmark happened when I tried to set up and enemy that would stalk my hero, but only on the x-axis. I tried setting up some variables on my objects but I couldn't find a way to change those in relation to another object.

In pseudocode it would be something like:
Code: Select all
if stalker.x < hero.x then stalker.x++
else if stalker.x > hero.x then stalker.x--
else stalker stand still


Any help would be greatly appreciated.
Last edited by Datasun on Thu Apr 03, 2014 8:54 pm, edited 1 time in total.
B
4
Posts: 12
Reputation: 263

Post » Thu Apr 03, 2014 11:12 am

@Datasun
Is this a side scroller where you want the stalker to start following the player if the player gets to the right of the stalker?

Or more of a top down view and you want the stalker to try to stay aligned with the player in the X axis?
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Thu Apr 03, 2014 9:02 pm

Hi, thanks for the reply! I was thinking of a (non-scrolling) platformer. Here's how I would represent it in words:

If the enemy is to the left of the main character the enemy would move right.
If the enemy is to the right of the main character the enemy would move left.
If the character and enemy is at the same x position the enemy would stop.

I just couldn't figure it out, so any help appreciated :)
B
4
Posts: 12
Reputation: 263

Post » Thu Apr 03, 2014 10:47 pm

Here you go. Any time the stalker isn't in line with the player's x value he will move to the player's x value. If you adjust the 0.02 you will adjust the speed at which the stalker aligns itself with the player.
You do not have the required permissions to view the files attached to this post.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Fri Apr 04, 2014 9:33 pm

Hey that's so nice of you, thank you very much, I relly appreciate it! It works perfectly. Now back to tinkering with my game. I guess I need to read the documentation and do some tutorials before thinking I can handle CS2 just like that.
B
4
Posts: 12
Reputation: 263


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests