Sending an AI character to different instances of objects


#1

Hi guys.

I’m new to Gdevelop and I am loving it. I have found most of my answers so far, thanks to the various tutorials online, but I would love a little help with this one issue.

In my game, I have different enemies on the screen, and when they can’t see the player anymore they need to return to their posts. I have created a enemyPost object, and they can be sent via pathfinding to this object. However, what I want to do is to create multiple instances of the enemyPost and send different enemy instances to different posts. I don’t want to have to create ten different enemy post objects, but rather, just the one and have different instances.

Does anyone know how I might implement this?

Thanks in advance.


#2

What I would do is place the instances of the enemy posts in the level, and then using event I would create an enemy for each post and link the enemy to the post. Then when you want to move the enemy back to the post, you can take in to account the post linked to enemy to move the enemy to that post.

So the event looks something like this:

At the beginning of the scene
->Repeat for each enemyPost object
—>Create enemy at position enemyPost.X(); enemyPost.Y()
—>Link enemyPost to enemy

And then when you want to move the enemy back to it position:
If enemy can not see the player
->Take in to account all enemyPost linked to enemy
->Move enemy to enemyPost

You going to need the For each loop and Object linking for this. You can find more information about them on the wiki.


#3

I dont really know what are you want to do exactly, but you dont need to use sprite objects as a target. if these posts position aren’t changeing dynamically, you can simply send enemies to a coordinate. when an enemy spawn, you can store tis X and Y coordinates in object variables. and later you can use these stored data to send its back. i think. i’m not tested it.


#5

Thanks ddabrahim

That’s perfect. It does the trick exactly as I wanted. I didn’t know about the linking. I’ve learned something valuable.

Thanks again.


#6

Thanks Gyuzko. Your suggestion was great. I will have to learn to use object variables effectively.

In this case, as it turned out, what I needed was a method to drop spawners in the level design process which would spawn an enemy and provide him with a post to return to later. ddabrahim’s suggestion gave me that functionality.

Thanks for the advice.