Skip to main content

251. Unity3d Tutorial - Setting Up Attack Types

See video

In this video, we will look at making the mob AI ignore the option to perform melee attacks of they are not within a predefined range of its target.

Tags:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Offline
Joined: Jun 3 2011

Hi peyet
here is some comments to make it better :
1- in the time when mob is in melee range, set the switch factor to 0 and don't use random generator, this will force mob to do the melee attack
2- the way you had done it, even when the mob targets home it will launch attacks on home ! to avoide that right after move(); put this block :
if (_target.name != _home.name)
{

}
and move all the code above state change in this block. this way the mob launches attacks only if the target is not home.
thanks

Offline
Joined: Jun 3 2011

Hi again
another recommendation is to use the public fload variables in AI script for range factors so that each mob can has it's own range attack also you can add three bool for setting if the mob can do melee, range, and magic and check for these bools to determine the switch factor so that if for example the mob is bird and it should have only ranged attack then you can set it or a wizard that has a bow and no sword can launch ranged and magic but no melee and a wizard with sword and no bow can do melee and magic but no ranged. this way you'll be able to cover all sort of mobs possible. I know that the logic for checking these conditions would be a bit tricky but not impossible. for example you can check for melee bool in start method and if it's unchecked then check for ranged then magic and set the baseMeleeRange (the distance mob will stop moving toward player) can be set accordingly etc. etc.
thanks