How do I make an enemy speed up when he spots the player?

Get help using Construct 2

Post » Sun May 10, 2015 3:41 am

Hey. Been trying to figure this one out for a while, but I'm stumped. I can get the enemy to speed up when he sees the player, but I can't get him to resume his normal speed when they player gets outta his view. I didn't like using the line of sight function 'cause, from what I understand, it's a circle around the enemy, so he's gonna spot the player even with his back turned.

Can anyone help?

Here's how I have it set up. I'm probably going the wrong way about this, but I'm making this up as I go.
Image
B
7
S
2
Posts: 60
Reputation: 604

Post » Sun May 10, 2015 4:51 am

first, comment your code.. this is not easy to look at.. you'll be doing yourself a favor when you don't look at it for a few months and return to it. :)

that Wait could be a problem since it's executing the wait and in that time the player might move out of range and then the max is then set to 130.

I would think about using distance() instead of X +/- might be easier to do.

sidenote: you should do less than or equal to 100, since the way you have it, the value 100 is not being represented at all. Your character is probably moving all over the place but technically you might want to cover 100. If some how the distance is 100 and player and sluggo are stationary.. no code will be executed.
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Sun May 10, 2015 10:24 am

easy. if it's using pathfinding and los:

condition - Los has view towards playerObject
action - set pathfinding maxspeed +50 (from current, can be 0), and also remember to set acceleration to some number like 1000 or so (so your object will speed up to current +50(or however much you set))
- regen obstacle map
- find path to playerObjectX, playerObjectY
- on path found (condition)
- move along path

though this will repeat itself each tick it might be hard on your CPU because of regenerating obstacle maps and stuff, so i recommend putting in first condition a "each 0.2 sec" - instead of each 0.017ms this is each 0.200 ms so it will burden your cpu less.

also you could pull regenerate obstacle map outside of this event if you have a static map
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Mon May 11, 2015 8:06 pm

Thanks, guys. I'll give it a go.
B
7
S
2
Posts: 60
Reputation: 604


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 23 guests