Jump to content

How is the boat animation handled in Shipwrecked?


_zwb

Recommended Posts

I've been looking though Shipwrecked scripts and animation files, but haven't quite figured out how were boats animations handled. As far as know it is part of the player animation and the actual boat entity itself is hidden when mounted, but I can't find the anim.bin file for boat animations, or any boat symbols I can override.

Does anyone know how were those created and how to make custom animations compatible with boats?

Link to comment
Share on other sites

I know an... unconventional method of making the boats appear on custom animations:
By using inst.components.driver:SplitFromVehicle() and inst.components.driver:CombineWithVehicle() you can visually make the boat appear under the Player's feet, these two functions are purely visual and will not actually dismount the Player from their boat. So, I'll give you an example below:

AddStategraphState("wilsonboating", GLOBAL.State {
		name = "perusal",
		tags = {"doing", "busy", "boating"},

		onenter = function(inst)
			inst.components.locomotor:StopMoving()
			inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_whoosh", nil, .1)
			inst.components.driver:SplitFromVehicle()	-- Visually split the boat from the Player!
			inst.AnimState:OverrideSymbol("book_cook", "wilson_journal", "book_wilson")
			inst.AnimState:PlayAnimation("reading_in")
			inst.AnimState:PushAnimation("reading_loop", true)
			
			local downvec = TheCamera:GetDownVec()
			local facedown = -(math.atan2(downvec.z, downvec.x) * (180/math.pi))
			inst.components.driver.vehicle.Transform:SetRotation(facedown)	-- Use this if you want the boat to face down!

			local timeout = math.random(1.2, 1.4)
			inst.sg:SetTimeout(timeout)
		end,

		onexit = function(inst)
			inst.components.driver:CombineWithVehicle()	-- Onexit make the boat combine back with the Player!
		end,

		timeline =
		{
			TimeEvent(8 * FRAMES, function(inst)
				inst.sg:RemoveStateTag("busy")
			end),
		},

		ontimeout= function(inst)
			inst:PerformBufferedAction()
			inst.sg:GoToState("perusal_pst")
		end,
	}
)

This is the code I used on the Wilson's New Horizons mod for the reading_loop animation from DST, I properly made use of the two functions SplitFromVehicle on onenter and CombineWithVehicle on onexit. You can also use this on onenter:

	local downvec = TheCamera:GetDownVec()
	local facedown = -(math.atan2(downvec.z, downvec.x) * (180/math.pi))
	inst.components.driver.vehicle.Transform:SetRotation(facedown)	-- Use this if you want the boat to face down!

To make the boat face the camera.

Link to comment
Share on other sites

5 hours ago, mathem99 said:

I know an... unconventional method of making the boats appear on custom animations:
By using inst.components.driver:SplitFromVehicle() and inst.components.driver:CombineWithVehicle() you can visually make the boat appear under the Player's feet, these two functions are purely visual and will not actually dismount the Player from their boat. So, I'll give you an example below:

AddStategraphState("wilsonboating", GLOBAL.State {
		name = "perusal",
		tags = {"doing", "busy", "boating"},

		onenter = function(inst)
			inst.components.locomotor:StopMoving()
			inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_whoosh", nil, .1)
			inst.components.driver:SplitFromVehicle()	-- Visually split the boat from the Player!
			inst.AnimState:OverrideSymbol("book_cook", "wilson_journal", "book_wilson")
			inst.AnimState:PlayAnimation("reading_in")
			inst.AnimState:PushAnimation("reading_loop", true)
			
			local downvec = TheCamera:GetDownVec()
			local facedown = -(math.atan2(downvec.z, downvec.x) * (180/math.pi))
			inst.components.driver.vehicle.Transform:SetRotation(facedown)	-- Use this if you want the boat to face down!

			local timeout = math.random(1.2, 1.4)
			inst.sg:SetTimeout(timeout)
		end,

		onexit = function(inst)
			inst.components.driver:CombineWithVehicle()	-- Onexit make the boat combine back with the Player!
		end,

		timeline =
		{
			TimeEvent(8 * FRAMES, function(inst)
				inst.sg:RemoveStateTag("busy")
			end),
		},

		ontimeout= function(inst)
			inst:PerformBufferedAction()
			inst.sg:GoToState("perusal_pst")
		end,
	}
)

This is the code I used on the Wilson's New Horizons mod for the reading_loop animation from DST, I properly made use of the two functions SplitFromVehicle on onenter and CombineWithVehicle on onexit. You can also use this on onenter:

	local downvec = TheCamera:GetDownVec()
	local facedown = -(math.atan2(downvec.z, downvec.x) * (180/math.pi))
	inst.components.driver.vehicle.Transform:SetRotation(facedown)	-- Use this if you want the boat to face down!

To make the boat face the camera.

I've tried showing boat entity before making this post, it sort of works but the issue is the boat itself isn't at the same position as the boat in player's animation:wilsondisappointed: Any ideas how to solve that? Maybe I could move the boat a bit to fit the animation?

Link to comment
Share on other sites

35 minutes ago, _zwb said:

I've tried showing boat entity before making this post, it sort of works but the issue is the boat itself isn't at the same position as the boat in player's animation:wilsondisappointed: Any ideas how to solve that? Maybe I could move the boat a bit to fit the animation?

Hmm... the only thing I can think of is making the boats be a little upwards in their idle state (whenever the player isn't riding it/when you split it with inst.components.driver:SplitFromVehicle() so this should work:
 

AddComponentPostInit("driver", function(self)
    local _OnUpdate = self.OnUpdate
    function self:OnUpdate(dt)
        _OnUpdate(self, dt)
        if self.vehicle ~= nil and self.vehicle:IsValid() then
            local CameraRight = GLOBAL.TheCamera:GetRightVec()
            local CameraDown = GLOBAL.TheCamera:GetDownVec()

            local myPos = self.inst:GetPosition()
            local displacement = CameraRight:Cross(CameraDown) * 0.05

            local pos = myPos - displacement

            self.vehicle.Transform:SetPosition(pos:Get())
        end
    end
end)

Try it with this on your modmain.lua

Link to comment
Share on other sites

On 9/13/2023 at 1:02 PM, mathem99 said:

Hmm... the only thing I can think of is making the boats be a little upwards in their idle state (whenever the player isn't riding it/when you split it with inst.components.driver:SplitFromVehicle() so this should work:
 

AddComponentPostInit("driver", function(self)
    local _OnUpdate = self.OnUpdate
    function self:OnUpdate(dt)
        _OnUpdate(self, dt)
        if self.vehicle ~= nil and self.vehicle:IsValid() then
            local CameraRight = GLOBAL.TheCamera:GetRightVec()
            local CameraDown = GLOBAL.TheCamera:GetDownVec()

            local myPos = self.inst:GetPosition()
            local displacement = CameraRight:Cross(CameraDown) * 0.05

            local pos = myPos - displacement

            self.vehicle.Transform:SetPosition(pos:Get())
        end
    end
end)

Try it with this on your modmain.lua

This works for me, just need to change the number a bit so the animation match

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...