Jump to content

[Question] Basics knowledge about IA ?


Recommended Posts

Hi,

I would like to create a variation of an existing monster. Currently the monster is neutral and i want it to be agressive. At least, on the player. But i don't know where to start to look.


Also, what define what monster attack what ? Like tentacle are hostile to pretty much everything, frogs don't attack spider, ... ?

Link to comment
Share on other sites

Behaviours: Define actions to take.

Brains: Define what Behaviours to do in a behaviour tree model.  Can have priorities.

 

So your monster would have a brain that has a priority tree to look for players to target as a behaviour, which suggests the targets to its combat component.

Other actions to take in the brain are wandering, panicking if on fire, etc.

Link to comment
Share on other sites

Ok, i tried to look at brains, and they have a chaseandattack function, but in this i don't see anything specific about what they target. Most nodes look like :

 

            ChaseAndAttack(self.inst, MAX_CHASE_TIME, MAX_CHASE_DIST),

Anyway, thanks for your help :)

Link to comment
Share on other sites

6 minutes ago, Lumina said:

Ok, i tried to look at brains, and they have a chaseandattack function, but in this i don't see anything specific about what they target. Most nodes look like :

 


            ChaseAndAttack(self.inst, MAX_CHASE_TIME, MAX_CHASE_DIST),

Anyway, thanks for your help :)

Look at the 'chaseandattack.lua' file in the behaviours folder for more of a description as to what the behaviour does.

Each behaviour node when being called from the Brain will call the 'Visit' function and expects a status variable for determining if it should stop or continue.

Link to comment
Share on other sites

@Lumina are you sorted here?

This can be easy or hard based on what monster you want to clone/adjust. Firstly, do you want to change the existing monster or introduce a new one? Does the existing thing already ever attack anything? If it does, this might be as simple as cloning the prefab and overwriting the target/ontarget/retargetfn functions. Let me know where you are with this?

Link to comment
Share on other sites

@mrboosch

I would like to introduce a new koalefant monster, but instead of being afraid of the player, it will attack it when the player is close. This is the basic. Ideally i would like to understand what define the way some monster attack everythings and some will attack some monster but not some others (for example, usually, spider doesn't attack beefalo without provocation, or frog/spider usually don't fight each others, but they are attacking pig if they don't have better target, and i don't know where it's defined)

Link to comment
Share on other sites

10 minutes ago, Lumina said:

@mrboosch

I would like to introduce a new koalefant monster, but instead of being afraid of the player, it will attack it when the player is close

With something like that, you could probably get away with just altering a koalefant brain without having to edit any behaviors.

function KoalefantBrain:OnStart()
    local root = PriorityNode(
    {
        WhileNode(function() return self.inst.components.hauntable ~= nil and self.inst.components.hauntable.panic end, "PanicHaunted", Panic(self.inst)),
        WhileNode(function() return self.inst.components.health.takingfiredamage end, "OnFire", Panic(self.inst)),
        ChaseAndAttack(self.inst, MAX_CHASE_TIME),
        SequenceNode{
            FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn, 0.5),
            RunAway(self.inst, ShouldRunAway, RUN_AWAY_DIST, STOP_RUN_AWAY_DIST)
        },
        FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn),
        BrainCommon.AnchorToSaltlick(self.inst),
        Wander(self.inst)
    }, .25)

    self.bt = BT(self.inst, root)
end

^^^ Thats an unedited copy of the priority node in the Koalefantbrain.lua, the basic structure of it's behaviors. Every time the brain cycles, it starts from the top and goes down the line of behaviors until it finds a behavior that is eligible to have it's attention. (if it's on fire, it will run the "onfire" node and nothing else below it will run. if a player is within it's attack range, it will run ChaseAndAttack, and nothing else below it will run. (except in some instances, but lets not complicate things))

Even though the ChaseAndAttack node is above the RunAway sequence node, I bet that the runaway node has a much higher range than the attack node, meaning that the attack node wont be able to take priority over the runaway node until the player gets close enough to be withing its specified aggro range. I think.

If you wanted a Koalefant that attacks instead of running away, I bet you could just comment out those four lines of the sequence node that house the runaway node. (You might also decide to increase the range of the chaseandattack somehow, assuming that it was a little on the low side)

Link to comment
Share on other sites

@pickleplayer I think you've got half the picture here. The brain should get altered, as it needs to know that 'fight' is more of a priority than run - Ranges might be the right culprit there at first glance.

I also think you need to alter the koalaphant's targeting functions (keep target, retarget) as well. For example, to do this SUPER quickly (and without much testing at all beyond logging in and getting attacked, I did the following steps)

  • Altered koala brain to remove characters as scary people function
local function ShouldRunAway(guy)
    return --[[ pulled out this part guy:HasTag("character") and --]] not guy:HasTag("notarget")
end

 

  • copied onnewtarget, retargetfn and keeptargetfn from hound.lua to koalaphant.lua, removing hound-specific logic
local function OnNewTarget(inst, data)
    if inst.components.sleeper:IsAsleep() then
        inst.components.sleeper:WakeUp()
    end
end

local function retargetfn(inst)
    return FindEntity(
            inst,
            TUNING.HOUND_TARGET_DIST,
            function(guy)
                return inst.components.combat:CanTarget(guy)
            end,
            nil,
            nil
        )
end

local function KeepTarget(inst, target)
    return inst.components.combat:CanTarget(target) 
end
  • Then last in koalaphant.lua I updated the commonfn to use my new functions and wake up if you're nearby:
inst.components.combat:SetKeepTargetFunction(KeepTarget)
inst.components.combat:SetRetargetFunction(3,retargetfn)
inst:ListenForEvent("newcombattarget", OnNewTarget)

Let me know your own results?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...