Got multiple instances of AI with Spriter animations working

Discussion and feedback on Construct 2

Post » Thu Nov 27, 2014 9:09 pm

Had to get this off my chest as it was a mind f$$k.

I made a bad guy with blind spots that patrols the level with collision detection while also using spriter animations. If it spots the player it aims its gun in the players direction and fires bullets at the player. This was pretty straight forward apart from a quirk with spawning bullets from the end of the gun in a spriter animation!

So I placed two bad guys in the level and suddenly I had to have a way of the game knowing which objects belonged to which AI. For instance I had the following problems.

-An AI detected an obstacle so it is told to turn around. However all AI would turn around.
-An AI detects the player and aims at it yet all AI aim the gun at the player but only one AI is spawning the bullets (Not the correct one either).
-Finding out the gun position within a spriter animation when the spriter plugin has constructed each animation instance.

Its done now and it's all pretty cool. I think I need a beer!
ImageImageImageImageImage
B
19
S
5
G
1
Posts: 614
Reputation: 2,542

Post » Fri Nov 28, 2014 8:50 pm

How did you solve this? I'm having a problem picking instances of spriter objects when using multiples of the same object. Please help!
B
4
Posts: 4
Reputation: 208

Post » Sat Nov 29, 2014 10:08 am

@jaredhd

So what you do is make sure you duplicate all the objects associated with one instance. i.e. Spriter object (SpriterObject), the Sprite object you attach the spriter object to (TextureObject), etc. Then for each of theses objects you set a variable called SpriterNo and set it to the same number for each group of objects. So each instance is made of objects who each have have the same variable with the same number unique to that instance.

Then you use the following actions to make sure each instance is given it's own command.

Foreach [SpriterObject]
Pick [TextureObject] that [TextureObject.SpriterNo] = [SpriterObject.SpriterNo]
...Add sub actions here...

So this loops through each Spriter object and grabs the Sprite object associated with it.

However, If you want to command a specific instance then you can instead do the following.

Pick [SpriterObject] that [SpriterObject.SpriterNo] = 1
Pick [TextureObject] that [TextureObject.SpriterNo] = 1
...Add sub actions here...
ImageImageImageImageImage
B
19
S
5
G
1
Posts: 614
Reputation: 2,542

Post » Sun Nov 30, 2014 2:25 am

For even more fun, make your object a container and throw in a dictionary or array... :mrgreen:
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests