If in range of actor.

Rawr

  • Posts: 85
Yeah. Anyone know how to do it? I'm trying to make a sidescrolling game, and I want actors to attack only when in range of the player.

AnachroNia

  • Posts: 72
Regions :)

Custom function :)
You have Actor 1 x,y ; Actor 2 x,y
Distance = sqrt((x1-x2)^2+(y1-y2)^2) (pythagorean theorem)
And if you make this line between the 2 actors - you can check if it collides with something :) (So the actors can't see thru walls)

Rawr

  • Posts: 85
Yeah it works...kinda. But it LAGS LIKE HELL. Is it possible to set that to let it check like, once a second?

coleislazy

  • *
  • Posts: 2607
In the "when created" section of your behavior, put a "do every x seconds" block and put that inside.

AnachroNia

  • Posts: 72
You can remove the sqrt - just when you set the distance - make it Distance = distance^2 (calculating only once) :)

Rawr

  • Posts: 85
Hey wait...I found out I can't set the actor attributes when attaching it as a actor behavior. Now what?

kantieno

  • Posts: 242
try using a scene behavior that detects it and then have it message the actors
Play my new game "Hidden Valley Ninja" here: http://www.kongregate.com/games/kantieno/hidden-valley-ninja

coleislazy

  • *
  • Posts: 2607
You just need to add a "for each actor of type" block from Scene->Actors and select the player actor type from the dropdown. Then, set the attribute you are using to store the player to "the actor" block that appears below the "for each actor" block. Just stick that in the "when created" wrapper of the behavior on your enemy.