Jump to content

Recommended Posts

I am currently making a mod that adds some creatures built entirely from scratch. So far, everything's going peachy; the creature acts like it's supposed to, animates when it's supposed to, the whole nine yards. The only problem is that, when walking, the creature will only face right, never to the left, so it's often just walking backwards.

 

I'm not sure what the problem is. The stategraph is working fine, the "canrotate" tag is added where it's supposed to, the brain is working, everything seems to be in order except for that one stupid thing.

 

I've been working on this for a few days now, to no avail. Any ideas as to what the problem is?

I may be mistaken, but I believe the "canrotate" tag has to do with changing the movement direction in the middle of the animation. probably mistaken

 

Does the creature use a different animation for up/down? If so is that working?

 

 

Edited by Corrosive

The creature does have different animation files for up and down, but visually they're identical to the side ones (it's a long worm creature, and perspective is hard). Just to test, though, I changed the up and down animations, and they did not work; the creature kept using just its facing-right walk animation.


The creature does have different animation files for up and down, but visually they're identical to the side ones (it's a long worm creature, and perspective is hard). Just to test, though, I changed the up and down animations, and they did not work; the creature kept using just its facing-right walk animation.

That is interesting.  If you're willing to attach (or send me directly if you are uncomfortable with that) files pertaining to the creature*, I'm more than happy to fiddle around with it to see if I can discern why that's happening.

 

 

*compiled, as would be included in the finished product-- the .zip with the animations and the prefab/stategraph files

Edited by Corrosive

The stategraph:

require("stategraphs/commonstates")local actionhandlers = {}local events={	CommonHandlers.OnStep(),	CommonHandlers.OnLocomote(false,true),    EventHandler("death", function(inst) inst.sg:GoToState("death") end),	    EventHandler("doattack", function(inst, data)         if not inst.components.health:IsDead() and not inst.sg:HasStateTag("busy") and data and data.target then             inst.sg:GoToState("attack", data.target)         end     end),		EventHandler("attacked", function(inst)         if not inst.components.health:IsDead() then             if not inst.sg:HasStateTag("attack") then -- don't interrupt attack or exit shield                inst.sg:GoToState("hit") -- can still attack            end        end     end),	    EventHandler("locomote", function(inst)         if not inst.sg:HasStateTag("busy") then                        local is_moving = inst.sg:HasStateTag("moving")            local wants_to_move = inst.components.locomotor:WantsToMoveForward()            if not inst.sg:HasStateTag("attack") and is_moving ~= wants_to_move then                if wants_to_move then                    inst.sg:GoToState("moving")                else                    inst.sg:GoToState("idle")                end            end        end    end),  	}local states={	--This handles the idle state.    State{        name = "idle",        tags = {"idle", "canrotate"},        onenter = function(inst, playanim)            inst.AnimState:PlayAnimation("idle", true)        end,    },		State{		name = "moving",        tags = {"canrotate", "moving", "walk"},        onenter = function(inst)            inst.components.locomotor:RunForward()            inst.AnimState:PlayAnimation("walk", true)               end,    },        State{        name = "attack",        tags = {"attack", "busy"},                onenter = function(inst, target)            inst.Physics:Stop()            inst.components.combat:StartAttack()            inst.AnimState:PlayAnimation("atk")            inst.sg.statemem.target = target        end,                timeline=        {            TimeEvent(25*FRAMES, function(inst) inst.components.combat:DoAttack(inst.sg.statemem.target) end),        },                events=        {            EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),        },    },	    State{        name = "hit",        tags = {"busy"},                onenter = function(inst)            inst.AnimState:PlayAnimation("hit")            inst.Physics:Stop()                    end,                events=        {            EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),        },    },		State{        name = "death",        tags = {"busy"},                onenter = function(inst)            inst.SoundEmitter:PlaySound(SoundPath(inst, "die"))            inst.AnimState:PlayAnimation("death")            inst.Physics:Stop()            RemovePhysicsColliders(inst)                        inst.components.lootdropper:DropLoot(Vector3(inst.Transform:GetWorldPosition()))                    end,    },   }return StateGraph("wormspider", states, events, "idle", actionhandlers)

The brain:

require "behaviours/follow"require "behaviours/wander"require "behaviours/chaseandattack"local WormspiderBrain = Class(Brain, function(self, inst)    Brain._ctor(self, inst)end)local MIN_FOLLOW = 1local MAX_FOLLOW = 11local MED_FOLLOW = 5local MAX_WANDER_DIST = 12local MAX_CHASE_TIME = 10local function GetFaceTargetFn(inst)    return inst.components.follower.leaderendlocal function KeepFaceTargetFn(inst, target)    return inst.components.follower.leader == targetendfunction WormspiderBrain:OnStart()    local root = PriorityNode(    {		ChaseAndAttack(self.inst, MAX_CHASE_TIME),		Follow(self.inst, function() return self.inst.components.follower.leader end, MIN_FOLLOW, MED_FOLLOW, MAX_FOLLOW, true),		--FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn),        Wander(self.inst, function() return Point(GetPlayer().Transform:GetWorldPosition()) end , MAX_WANDER_DIST)            }, .5)            self.bt = BT(self.inst, root)         endreturn WormspiderBrain

The Spriter animation files are:

atk_up / _side / _down

walk_up / _side / _down

idle

death

hit

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
×
  • Create New...