Enemy Distance

0 favourites
  • 7 posts
From the Asset Store
Give Sound to the enemies that are part of your game! :)
  • Hey there. I haven't posted for a loooong time. BUT, I'm making something (again) and I really need a hand. I went through about 70 of the forum pages looking for the answer I need, but I can't quite seem to find anything I'm looking for, so my question is this.

    How can I make it so that if the player is WITHIN a certain distance of the enemy, the enemy say... For simplicity rotates. Like, WITHIN -10 of it's x and +10 of it's x. The WITHIN part is very important, hence the capitalization. If someone could help me out here, it would be very much appreciated. (I've been stuck on this for about 5 hours now. So it's probably really easy, but I can't get it at all.)

    Thanks in advance.

  • Create a System->Compare Two Values event. Then go to System and find the distance function. (It's under Math.) Plugin the player and enemy's X and Y properties. Example: distance(Player.x, Player.Y, Enemy.X, Enemy.Y). Then change equals to less than, and type a number in the second box for the distance (in pixels).

  • Oh maaaaan, Thanks a bunch I didn't realize that function existed. Sheeeesh. I appreciate you. :B

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Okay so, I have it. But it only works once, I can't get it to work for multiple instances within the MONSTERS family. Any ideas?

    Also, it's a platformer. So basically I want it so that once you're out of that say, 15 pixel range, it goes back to not rotating.

  • Here's an example I put together which I think does what you want:

    http://dl.dropbox.com/u/47015043/construct2/sentry-example.capx

    It's for a top-down configuration rather than a platformer, but the principles should be the same.

    It uses invisible sprites pinned to the sentries which act as radar/sight. I've made the sprites visible in the example so it's easier to see the effect. Also, I've only used 8 collision points in the radar, but you could use more to make it more like a circle.

  • Another approach uses an instance variable (distance) in each enemy instance, which is set every tick using the distance function.

    <img src="http://dl.dropbox.com/u/6109058/reactToPlayerEvents.JPG" border="0" />

  • Great thanks a lot guys. I've got it all figured out now. Got it set up so that if you're within the range it starts, and if you're out of the range it stops. I just hope that it doesn't get too laggy or anything, considering I'll have many objects eventually.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)