maliblues Posted August 28, 2019 Share Posted August 28, 2019 Hi there. I've been working on a creature mod, using the beefalo code as a base. I'm still learning so any help on this would be really appreciated. So I have been trying to make the creature flee when health is below 20%. I tried adding the RunAway behaviour to the Brain PriorityNode: WhileNode(function() return self.inst.components.health:GetPercent() < 0.20 end, RunAway(self.inst, ShouldRunAway, RUN_AWAY_DIST, STOP_RUN_AWAY_DIST)), (I wanted the creature to run away from the attacker not just any character/player so the code for ShouldRunAway isn't ideal.) local function ShouldRunAway(guy) return guy:HasTag("character") and not guy:HasTag("notarget") end My problem was that when the player attacks the creature, the creature fights back as intended but when health gets below 20% it stops attacking and stands there playing idle animations, when health has regenerated above 20% it comes back to continue fighting. So on the creature prefab I added the code below for the OnAttacked function: if inst.components.combat:HasTarget() and inst.components.health:GetPercent() < 0.20 then --inst.components.combat:GiveUp() inst.components.combat:DropTarget() end Now the creature doesn't come back to continue fighting however when health is below 20% it still does not run away. I'm also not sure if I should be adding something to the brain or prefab script to achieve what I want. Mostly just been guessing and learning through trial and error so any insight into what I can do here will help! Ty for reading Link to comment Share on other sites More sharing options...
Thomas Die Posted August 28, 2019 Share Posted August 28, 2019 it might be becuase of you distance and stop run away distance drop target removes the player as a threat Link to comment Share on other sites More sharing options...
maliblues Posted August 28, 2019 Author Share Posted August 28, 2019 (edited) Hmm, I had kept my distance and stop run away distance same to what the koalefant uses. However I found a similar code in the Bunnyman brain file and it seems to be working correctly now! WhileNode(function() return self.inst.components.health:GetPercent() < TUNING.BUNNYMAN_PANIC_THRESH end, "LowHealth", ChattyNode(self.inst, "RABBIT_RETREAT", RunAway(self.inst, "scarytoprey", SEE_PLAYER_DIST, STOP_RUN_DIST))), edit: also related code on the bunnyman prefab inst.components.combat.panic_thresh = TUNING.BUNNYMAN_PANIC_THRESH Edited October 9, 2019 by maliblues Link to comment Share on other sites More sharing options...
Thomas Die Posted August 29, 2019 Share Posted August 29, 2019 that's good to know , you should always use the base code as refrence Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now