Jump to content

Creature Sprite Not Rotating


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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...