Jump to content
  • Advertisement
Sign in to follow this  
Longclaws

Specfic AI scripting question

This topic is 714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been working on an AI code for my game for a while, watching lots of tutorials and reading a fair bit of material on how to write the code, but no where have I seen any code that is close to what I am needing.  I am attempting a zombie game that, similarly to Stubbs the Zombie: Rebel without a Pulse, will allow an enemy target to "die" and then come back as a friendly target soon after.  The 2 stages will have different AI behavior and use different animations as well as models, if I can swing it.  I've gotten as far as the basic AI for each stage, but am unsure of how to combine them.  Would it be best to set them to different conditions, such as the "enemies" receiving one type of damage to a certain point, then going through the change animation, changing the conditions on their friend or foe behavior, then receiving a different type of damage?  Or would I need two different scripts, with one for enemy AI and another for friendly, with a condition that selects which one is running?  I'd really appreciate the assist on this.

Share this post


Link to post
Share on other sites
Advertisement

Or would I need two different scripts, with one for enemy AI and another for friendly, with a condition that selects which one is running?  I'd really appreciate the assist on this.

 

in general this sounds like the better way to do it. you really have two types of units, non-zombie, and zombie. when a non-zombie dies, after a period of time, you change the unit type to zombie. you can do your transform animations just before you change them to a zombie.

 

how well this approach fits with unity, that's an entirely different question.

Share this post


Link to post
Share on other sites
The 2 stages will have different AI behavior and use different animations as well as models, if I can swing it

Based on this I would go a step further and spawn a new game object for the friendly entity after the enemy entity dies, effectively replacing the enemy with the friendly. This is the easiest solution I can think of. The only downside is that if other game objects hold a reference to the original enemy and want to keep the reference after it transforms, then you would need to update these references somehow.

Edited by Andor Patho

Share this post


Link to post
Share on other sites

I am trying to streamline as much of this process as I can in the scripting so that other aspects won't need as much tweaking, since animation really won't be my strong point.  I was rolling it around in my head a bit more, and wanted to run this by someone.  Under normal circumstances, an NPC in this case would just have a health variable, but what if I added a second variable such as "humanity" and when that dropped to zero the npc would change into a zombie.  As for the code, first it would conditionally determine if humanity > 0, if so it runs the human script.  If humanity <= 0, it runs zombie script.  Health can be a separate variable for destroying game objects.  Would this be an effective method, or would running this much code cause an issue?

Share this post


Link to post
Share on other sites

You could do that, but it's better to separate things into their own "blocks" when you can.

It will likely be less code in total, and if there's a bug with a spawned zombie, you know that the normal NPC code doesn't have anything to do with it (it doesn't even exist for the zombie!).

It also means that you're able to make humanoids spawn into other things more easily -- e.g. there's a 1/10 chance that it spawns a super-zombie (which is also a unique type).

Share this post


Link to post
Share on other sites

 

The 2 stages will have different AI behavior and use different animations as well as models, if I can swing it

Based on this I would go a step further and spawn a new game object for the friendly entity after the enemy entity dies, effectively replacing the enemy with the friendly. This is the easiest solution I can think of. The only downside is that if other game objects hold a reference to the original enemy and want to keep the reference after it transforms, then you would need to update these references somehow.

 

 

I would never do this in Unity as a principle. The single biggest performance hogs in Unity are the "Instantiate" and "Destroy" Methods.

 

Use them at startup to create pools of objects large enough to last you through the whole level. That way, you don't run into bottlenecks at times when lots of stuff is going on on screen and tons of "Instantiate" and "Destroy" Methods are called in the background. On a weaker machine, your framerate will drop immidiatly if this happens.

And as said, given you are not bound by a small as hell RAM, pre-allocating things to pools at the beginning and getting what you need from the pools is fairly easy.

 

 

Now, in Unity activating/deactivating scripts is extremly easy as long as you are using the bogstandart game objects. Assign both scripts, enemy and player AI, to your game object, deactivate what shouldn't run at first in the editor, activate the other and deactivate the originally activated one during "transformation" from Enemy to Zombie.

Edited by Gian-Reto

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!