Enemy Interactions

What is the simplest way to do the following?

Create spawn points for mobs\enemys?
Get Enemies to interact, like chase & attack the player?
Is there a way to have Enemies wander aimlessly until a player comes close enough?

Thanks in advanced!

1 Like

Create spawn points for mobs\enemys

Depend if you want them to spawn randomly, or if you already know where you want them to spawn.
You can when you create an object, put the value of where you want the ennemies to spawn for exemple X 100 and Y 100, so you can use the create object function like “create ennemies X:100 Y:100”
Or, if you want them to spawn where there is a spawn object, then you can change X : 100 by X : NameOfTheSpawnPointObect.X()
same for Y and they would spawn at the spawn point object

Get Enemies to interact, like chase & attack the player

Again, depend, if you want them to interact depend on the position of the ennemy and the player, so you can use the distance function

Enemies wander aimlessly until a player comes close enough

Yeah, using the distance function, like “distance between ennemies and player is > 100 then wander aimlessly” prntscr.com/ijvtp3

Most of those questions were previously asked by other people, pretty sure you can find answer by searching in the forum :stuck_out_tongue:

For the random aim GD has a very useful action “Rotate object”, you can use this action with a random angle (expression: Random(360)) and an angular speed and GD will rotate the object smoothly to the given target angle, if you do it every X seconds the enemy will look around randomly.
The raycast condition has been merged, so you can already use it, if the player is close enough (as Jeje2201 suggests) launch a ray from the enemy position in the enemy looking direction and check for intersecion with the player, if there is an intersection the enemy can see the player so stop chasing and add a force in the player direction, or use the pathfinding behavior if there are obstacles :slight_smile:

1 Like

Hi Gent’s thanks for the advice. I will give it a go and report back.

Just on this - they will spawn to the edge of the viewport and wonder in. How would you go about creating the events to achieve this? I was originally going to have them created when the scene was created, but think now it would be better to have them enter a few seconds after, and then and varying intervals from then on. From there spawn point they would then be attracted to the player.

What events would you use to do this?