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

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


 1
 2二六五.动力飞行帽(戴羽毛帽在天空自由飞翔)
 3
 4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/hats.lua文件,将下列内容:
 5
 6	local function feather_equip(inst, owner)
 7		onequip(inst, owner)
 8		local ground = GetWorld()
 9		if ground and ground.components.birdspawner then
10			ground.components.birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY_FEATHERHAT)
11			ground.components.birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX_FEATHERHAT)
12		end
13	end
14	local function feather_unequip(inst, owner)
15		onunequip(inst, owner)
16		local ground = GetWorld()
17		if ground and ground.components.birdspawner then
18			ground.components.birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY)
19			ground.components.birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX)
20		end
21	end
22	local function feather()
23		local inst = simple()
24		
25		inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL
26		
27		inst.components.equippable:SetOnEquip( feather_equip )
28		inst.components.equippable:SetOnUnequip( feather_unequip )
29		
30		inst:AddComponent("fueled")
31		inst.components.fueled.fueltype = "USAGE"
32		inst.components.fueled:InitializeFuelLevel(TUNING.FEATHERHAT_PERISHTIME)
33		inst.components.fueled:SetDepletedFn(generic_perish)
34
35	替换为:
36
37local function feather_equip(inst, owner)
38	onequip(inst, owner)
39	local shadow = GetPlayer().entity:AddDynamicShadow()
40	shadow:SetSize( 0, 0 )
41	inst.task = inst:DoPeriodicTask(.01, function() owner.Physics:SetMotorVelOverride(20,10,0) end )
42	inst:DoTaskInTime(3, function() 
43		if inst.task then inst.task:Cancel() inst.task = nil end
44		inst.task = inst:DoPeriodicTask(.01, function() owner.Physics:SetMotorVelOverride(20,1,0) end)
45	end )
46end
47local function feather_unequip(inst, owner)
48	if inst.task then inst.task:Cancel() inst.task = nil end
49	inst.task = inst:DoPeriodicTask(.01, function() owner.Physics:SetMotorVelOverride(20,-10,0) end)
50	inst:DoTaskInTime(3, function() 
51		if inst.task then inst.task:Cancel() inst.task = nil end
52		onunequip(inst, owner)
53		local shadow = GetPlayer().entity:AddDynamicShadow()
54		shadow:SetSize( 1.3, .6 )
55	end)
56end
57local function feather()
58	local inst = simple()
59	inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL
60	inst.components.equippable:SetOnEquip( feather_equip )
61	inst.components.equippable:SetOnUnequip( feather_unequip )
62
63	即可在戴羽毛帽时开始起飞,爬升3秒后平飞,用键盘WSAD键控制方向。想降落时卸载羽毛帽即可开始着陆,落地后会滑行一段(按WSAD键可以减少滑行距离)。注意不要在爬升阶段卸载羽毛帽(平飞时再卸载即可),否则在惯性作用下将滑出很长一段距离