代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。

原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html



二六五.动力飞行帽(戴羽毛帽在天空自由飞翔)

	用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/hats.lua文件,将下列内容:

	local function feather_equip(inst, owner)
		onequip(inst, owner)
		local ground = GetWorld()
		if ground and ground.components.birdspawner then
			ground.components.birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY_FEATHERHAT)
			ground.components.birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX_FEATHERHAT)
		end
	end
	local function feather_unequip(inst, owner)
		onunequip(inst, owner)
		local ground = GetWorld()
		if ground and ground.components.birdspawner then
			ground.components.birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY)
			ground.components.birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX)
		end
	end
	local function feather()
		local inst = simple()
		
		inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL
		
		inst.components.equippable:SetOnEquip( feather_equip )
		inst.components.equippable:SetOnUnequip( feather_unequip )
		
		inst:AddComponent("fueled")
		inst.components.fueled.fueltype = "USAGE"
		inst.components.fueled:InitializeFuelLevel(TUNING.FEATHERHAT_PERISHTIME)
		inst.components.fueled:SetDepletedFn(generic_perish)

	替换为:

local function feather_equip(inst, owner)
	onequip(inst, owner)
	local shadow = GetPlayer().entity:AddDynamicShadow()
	shadow:SetSize( 0, 0 )
	inst.task = inst:DoPeriodicTask(.01, function() owner.Physics:SetMotorVelOverride(20,10,0) end )
	inst:DoTaskInTime(3, function() 
		if inst.task then inst.task:Cancel() inst.task = nil end
		inst.task = inst:DoPeriodicTask(.01, function() owner.Physics:SetMotorVelOverride(20,1,0) end)
	end )
end
local function feather_unequip(inst, owner)
	if inst.task then inst.task:Cancel() inst.task = nil end
	inst.task = inst:DoPeriodicTask(.01, function() owner.Physics:SetMotorVelOverride(20,-10,0) end)
	inst:DoTaskInTime(3, function() 
		if inst.task then inst.task:Cancel() inst.task = nil end
		onunequip(inst, owner)
		local shadow = GetPlayer().entity:AddDynamicShadow()
		shadow:SetSize( 1.3, .6 )
	end)
end
local function feather()
	local inst = simple()
	inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL
	inst.components.equippable:SetOnEquip( feather_equip )
	inst.components.equippable:SetOnUnequip( feather_unequip )

	即可在戴羽毛帽时开始起飞,爬升3秒后平飞,用键盘W、S、A、D键控制方向。想降落时卸载羽毛帽即可开始着陆,落地后会滑行一段(按W、S、A、D键可以减少滑行距离)。注意不要在爬升阶段卸载羽毛帽(平飞时再卸载即可),否则在惯性作用下将滑出很长一段距离