代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二四四.神奇跳跃(按键盘R键主角可向前跳跃)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/player_common.lua文件,在inst:AddComponent("resurrectable")的下一行插入以下内容:
5
6TheInput:AddKeyUpHandler(KEY_R, function()
7 inst.Physics:SetCollides(false)
8 inst:DoTaskInTime(0, function()
9 inst.AnimState:PlayAnimation("give")
10 inst.components.playercontroller:Enable(false)
11 inst.components.locomotor:Stop()
12 inst.Physics:SetMotorVelOverride(50,45,0) end )
13 inst:DoTaskInTime(0.2, function()
14 inst.Physics:ClearMotorVelOverride()
15 inst.Physics:SetMotorVelOverride(50,0,0) end )
16 inst:DoTaskInTime(0.3, function()
17 inst.Physics:ClearMotorVelOverride()
18 inst.Physics:SetMotorVelOverride(50,-25,0) end )
19 inst:DoTaskInTime(0.5, function()
20 inst.Physics:ClearMotorVelOverride()
21 inst.components.locomotor:Stop()
22 local pt = inst:GetPosition()
23 inst.Transform:SetPosition(pt.x, 0, pt.z)
24 inst.components.playercontroller:Enable(true)
25 inst.Physics:SetCollides(true)
26 inst.AnimState:PlayAnimation("idle")
27 inst.SoundEmitter:PlaySound("dontstarve/movement/bodyfall_dirt", "bodyfall") end )
28end )
29
30 即可按键盘R键,让主角向前跳跃,用以方便地越过沟壑、墙等障碍,也可以跳到海面上,渡海而行。当身边有障碍物时,会影响跳跃高度。将其中KEY_R替换为其他键,比如KEY_C,就可以按键盘C键跳跃