Jump to content

How to make bomerang anm spin?


Recommended Posts

You'll need to create a separate spinning animation in your exported/wand/wand.scml file.

Here are some relevant snippets of code from boomerang.lua:

local function OnThrown(inst, owner, target)
    if target ~= owner then
        owner.SoundEmitter:PlaySound("dontstarve/wilson/boomerang_throw")
    end
    inst.AnimState:PlayAnimation("spin_loop", true)
end

local function OnDropped(inst)
    inst.AnimState:PlayAnimation("idle")
end

These functions are called when the Boomerang is thrown or dropped (there are a few others in the file as well), and tell the game which animation to play. Here specifically, when a Boomerang is thrown, the game calls OnThrown which instructs the game to play the Boomerang's "spin_loop" animation.

You should create your custom animation in wand.scml, name it something memorable, and then tell the game to play that animation in your projectile's own OnThrown function (inst.components.projectile:SetOnThrownFn(OnThrown)). Then fill in the OnHit, OnMiss, etc. bits with functions to play either the "idle" or a different animation so that your weapon doesn't continue spinning until the end of time.

Edited by ShinyMoogle
Link to comment
Share on other sites

Two parts. First is creating the spin animation in your object's .scml file. You need to open up Spriter and create a new animation in the same .scml file that has your "idle" animation (exported/wand/wand.scml). It doesn't really matter what you name this, but since you'll be referring to the code from boomerang.lua, might as well keep a consistent naming scheme and name it "spin_loop". In that animation, make the thing spin. however you want it to spin.

On the code side of things, for the most part you can just copy the code for the boomerang's projectile component, as well as the corresponding functions. If you've named the animation "spin_loop" as I recommended earlier, there actually shouldn't be much else you need to do with the code, because the item's projectile functionality will be pretty much the same as the boomerang's.

If for some reason you would really rather have the animation named something like "spinnythingthrowanimation" then you would have to replace instances of inst.AnimState:PlayAnimation("spin_loop", true) with inst.AnimState:PlayAnimation("spinnythingthrowanimation", true) ... but I would not recommend going that route!

ALSO!

I just took another look at the code and the boomerang's OnFinished function (in the finiteuses component) has this nice little line:

local function OnFinished(inst)
    inst.AnimState:PlayAnimation("used")
    inst:ListenForEvent("animover", function() inst:Remove() end)
end

... which tells the game to play your weapon's "used" animation when all of its uses are consumed. I haven't opened up the .scml to check if you have one or not - but I'll take the liberty of assuming you haven't included one. If you have, great! But assuming you haven't, you'll either need to create an animation named "used" which shows the weapon breaking or something, or just take the easy way out:

Replace this in your main fn function:

inst.components.finiteuses:SetOnFinished(OnFinished)

With:

inst.components.finiteuses:SetOnFinished(inst.Remove)

 

Edited by ShinyMoogle
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...