Ileana_Saphira Posted September 11, 2023 Share Posted September 11, 2023 Hello, can anyone help me or explain how to make my character fly? I’m just looking and can’t find an answer to my question and how to add wings on which the character will fly since he is a butterfly... sorry for my broken English, I’m translating everything from a translator and I was really afraid to ask about it... and if there is no opportunity to give him this ability, then I’m sorry for wasting your time... Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/ Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Share Posted September 13, 2023 Hello, I have some suggestions for character flight. While I do not know of any flying characters, you can add code that would allow your character to jump far distances, such as across rivers and crevasses. The code I'd recommend using is from the fixed version of Frog Webber. You'll need to pull some assets such as the leapstaff component and animations for player_leap. They're found in DST's Mods folder, which is found by right-clicking DST on Steam, choosing "Manage" ---> "Browse Local Files", and finding: mods\workshop-2249540093\scripts\components The player_leap.zip file found in: mods\workshop-2249540093\anim I will paste the code I use personally to create jumping characters. It is edited so that it no longer requires a Walking Cane to use. You will have to paste the character's name over wherever I type "CHARACTER_NAME". Start by adding this tag into your local common_postinit found in your character's prefab file. inst:AddTag ("CHARACTER_NAME") Next you will post the following into your character's modmain.lua file. Please remember to replace any instances of "CHARACTER_NAME". If you are editing using Notepad++, you can press Ctrl + F to quickly check for all instances of "CHARACTER_NAME", although there's only one near the top. Also, remember to keep the quotation marks around the name. Spoiler local LEAP_MAX_DIST = 10 local LEAP_MIN_DIST = 3 local LEAP_MAX_SPEED = 16 local LEAP_MIN_SPEED = LEAP_MAX_SPEED * LEAP_MIN_DIST / LEAP_MAX_DIST local LEAP_MAX_DIST_SQ = LEAP_MAX_DIST * LEAP_MAX_DIST local LEAP_MIN_DIST_SQ = LEAP_MIN_DIST * LEAP_MIN_DIST local require = GLOBAL.require local STRINGS = GLOBAL.STRINGS local ACTIONS = GLOBAL.ACTIONS local FRAMES = GLOBAL.FRAMES local DEGREES = GLOBAL.DEGREES local COLLISION = GLOBAL.COLLISION local TheSim = GLOBAL.TheSim local State = GLOBAL.State local EventHandler = GLOBAL.EventHandler local TimeEvent = GLOBAL.TimeEvent local ActionHandler = GLOBAL.ActionHandler local Vector3 = GLOBAL.Vector3 local PlayFootstep = GLOBAL.PlayFootstep local SpawnPrefab = GLOBAL.SpawnPrefab ---------------------------------------------------------------------------------------------------------------- local leap_action = AddAction("LEAP", "leap", function(act) if act.doer ~= nil and act.doer.sg ~= nil and act.doer.sg.currentstate.name == "leap_pre" then act.doer.sg:GoToState("leap", { pos = act.pos }) return true end end) leap_action.priority = 10 leap_action.rmb = true leap_action.distance = 1024 AddComponentPostInit("playeractionpicker", function(self) if self.inst:HasTag("CHARACTER_NAME") then local LEAPACTION = GLOBAL.ACTIONS.LEAP local _GetRightClickActions = self.GetRightClickActions self.GetRightClickActions = function(self, position, target) local actions = _GetRightClickActions(self, position, target) if #actions == 0 then local ishungry = self.inst.replica.hunger:GetCurrent() < 10 local ispassable = self.map:IsPassableAtPoint(position:Get()) if ispassable and not ishungry then actions = self:SortActionList({LEAPACTION}, position) end end return actions end end end) -------------------------------------------------------------------------- AddStategraphState("wilson", State{ name = "leap_pre", tags = { "doing", "busy", "canrotate" }, onenter = function(inst) inst.components.locomotor:Stop() inst.AnimState:PlayAnimation("leap_pre") end, events = { EventHandler("animover", function(inst) if inst.AnimState:AnimDone() then if inst.bufferedaction ~= nil then inst:PerformBufferedAction() else inst.sg:GoToState("idle") end end end), }, }) local function ToggleOffPhysics(inst) inst.sg.statemem.isphysicstoggle = true inst.Physics:ClearCollisionMask() inst.Physics:CollidesWith(COLLISION.GROUND) end local function ToggleOnPhysics(inst) inst.sg.statemem.isphysicstoggle = nil inst.Physics:ClearCollisionMask() inst.Physics:CollidesWith(COLLISION.WORLD) inst.Physics:CollidesWith(COLLISION.OBSTACLES) inst.Physics:CollidesWith(COLLISION.SMALLOBSTACLES) inst.Physics:CollidesWith(COLLISION.CHARACTERS) inst.Physics:CollidesWith(COLLISION.GIANTS) end AddStategraphState("wilson", State{ name = "leap", tags = { "doing", "busy", "canrotate", "nopredict", "nomorph" }, onenter = function(inst, data) inst.components.locomotor:Stop() inst.AnimState:PlayAnimation("leap") local dist if data ~= nil and data.pos ~= nil then local pos = data.pos:GetPosition() inst:ForceFacePoint(pos.x, 0, pos.z) local distsq = inst:GetDistanceSqToPoint(pos) if distsq <= LEAP_MIN_DIST_SQ then dist = LEAP_MIN_DIST inst.sg.statemem.speed = LEAP_MIN_SPEED elseif distsq >= LEAP_MAX_DIST_SQ then dist = LEAP_MAX_DIST inst.sg.statemem.speed = LEAP_MAX_SPEED else dist = math.sqrt(distsq) inst.sg.statemem.speed = LEAP_MAX_SPEED * dist / LEAP_MAX_DIST end else inst.sg.statemem.speed = LEAP_MAX_SPEED dist = LEAP_MAX_DIST end if inst.components.hunger ~= nil then inst.components.hunger:DoDelta(-dist / LEAP_MAX_DIST, true) end local x, y, z = inst.Transform:GetWorldPosition() local angle = inst.Transform:GetRotation() * DEGREES if GLOBAL.TheWorld.Map:IsPassableAtPoint(x + dist * math.cos(angle), 0, z - dist * math.sin(angle)) then ToggleOffPhysics(inst) end inst.Physics:SetMotorVel(inst.sg.statemem.speed * .5, 0, 0) local fx = SpawnPrefab("small_puff") if fx ~= nil then fx.Transform:SetScale(.3, .3, .3) fx.Transform:SetPosition(x, 0, z) end PlayFootstep(inst) if inst.components.playercontroller ~= nil then inst.components.playercontroller:Enable(false) end end, onupdate = function(inst) if inst.sg.statemem.isphysicstoggle then local x, y, z = inst.Transform:GetWorldPosition() local angle = inst.Transform:GetRotation() * DEGREES local radius = .5 x = x + .75 * radius * math.cos(angle) z = z - .75 * radius * math.sin(angle) local ents = TheSim:FindEntities(x, 0, z, radius, { "wall" }) for i, v in ipairs(ents) do if v.components.health ~= nil and v.components.health:GetPercent() > .5 then ToggleOnPhysics(inst) return end end end end, timeline = { TimeEvent(.5 * FRAMES, function(inst) inst.Physics:SetMotorVel(inst.sg.statemem.speed * .75, 0, 0) end), TimeEvent(1 * FRAMES, function(inst) inst.Physics:SetMotorVel(inst.sg.statemem.speed, 0, 0) end), TimeEvent(19 * FRAMES, function(inst) inst.Physics:SetMotorVel(inst.sg.statemem.speed * .25, 0, 0) inst.SoundEmitter:PlaySound("dontstarve/movement/bodyfall_dirt") local fx = SpawnPrefab("small_puff") if fx ~= nil then fx.Transform:SetScale(.3, .3, .3) local x, y, z = inst.Transform:GetWorldPosition() local angle = inst.Transform:GetRotation() * DEGREES fx.Transform:SetPosition(x + .25 * math.cos(angle), 0, z - .25 * math.sin(angle)) end end), TimeEvent(20 * FRAMES, function(inst) inst.Physics:Stop() inst.sg:GoToState("idle", true) end), }, onexit = function(inst) if inst.sg.statemem.isphysicstoggle then ToggleOnPhysics(inst) end if inst.components.playercontroller ~= nil then inst.components.playercontroller:Enable(true) end end, }) AddStategraphState("wilson_client", State{ name = "leap_pre", tags = { "doing", "busy", "canrotate" }, onenter = function(inst) inst.components.locomotor:Stop() inst.AnimState:PlayAnimation("leap_pre") inst.AnimState:PushAnimation("leap_lag", false) inst:PerformPreviewBufferedAction() inst.sg:SetTimeout(2) end, onupdate = function(inst) if inst:HasTag("doing") then if inst.entity:FlattenMovementPrediction() then inst.sg:GoToState("idle", "noanim") end elseif inst.bufferedaction == nil then inst.sg:GoToState("idle") end end, ontimeout = function(inst) inst:ClearBufferedAction() inst.sg:GoToState("idle") end, }) AddStategraphActionHandler("wilson", ActionHandler(ACTIONS.LEAP, function(inst) return not inst.sg:HasStateTag("busy") and (inst.sg:HasStateTag("moving") or inst.sg:HasStateTag("idle")) and "leap_pre" or nil end)) AddStategraphActionHandler("wilson_client", ActionHandler(ACTIONS.LEAP, function(inst) return not (inst.sg:HasStateTag("busy") or inst:HasTag("busy")) and inst.entity:CanPredictMovement() and (inst.sg:HasStateTag("moving") or inst.sg:HasStateTag("idle")) and "leap_pre" or nil end)) -------------------------------------------------------------------------- local function ReticuleTargetFn() local player = GLOBAL.ThePlayer local ground = GLOBAL.TheWorld.Map local x, y, z for r = LEAP_MAX_DIST * .6, LEAP_MAX_DIST, .25 do x, y, z = player.entity:LocalToWorldSpace(r, 0, 0) if ground:IsPassableAtPoint(x, y, z) then return Vector3(x, y, z) end end for r = LEAP_MAX_DIST * .6 - .25, LEAP_MIN_DIST, -.25 do x, y, z = player.entity:LocalToWorldSpace(r, 0, 0) if ground:IsPassableAtPoint(x, y, z) then return Vector3(x, y, z) end end return Vector3(x, y, z) end I hope you find this useful! If this doesn't satisfy you, then I do apologize. The best I can offer other than this would be to attempt to reverse-engineer code from Gleenus' Airplane Mod. If there are any translation errors, please reply on this thread so that a native speaker may help translate in your native language. Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664832 Share on other sites More sharing options...
Ileana_Saphira Posted September 13, 2023 Author Share Posted September 13, 2023 (edited) @ViridianCrown small problem, it basically works but the character has disappeared... A! everything worked, I realized what I did wrong but another problem arose it doesn’t jump.... Edited September 13, 2023 by Ileana_Saphira Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664912 Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Share Posted September 13, 2023 1 hour ago, Ileana_Saphira said: @ViridianCrown small problem, it basically works but the character has disappeared... A! everything worked, I realized what I did wrong but another problem arose it doesn’t jump.... Ah! I completely forgot! You need to set a destination for the player_jump animation file in the character's preset file. Just go over to local assets at the top of your character's lua file and place this line between the parenthesis, preferably directly under any other files: Asset("ANIM", "anim/player_leap.zip"), Best of luck with the rest of the character! Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664931 Share on other sites More sharing options...
Ileana_Saphira Posted September 13, 2023 Author Share Posted September 13, 2023 (edited) ViridianCrown I did something wrong... I did something wrong... I even changed the player to the character name, for some reason an error appears... Edited September 13, 2023 by Ileana_Saphira Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664943 Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Share Posted September 13, 2023 Well, with the player_leap it keeps that name as the code searches specifically within the player_leap folder, so renaming it would break it. Hope this helps! So it should look: local MakePlayerCharacter = require "prefabs/player_common" local assets= { Asset( "SCRIPT", "scripts/prefabs/player_common.lua" ) Asset( "ANIM", "anim/charax.zip" ) Asset( "ANIM", "anim/ghost_charax_build.zip" ), Asset( "ANIM", "anim/player_leap.zip" ), } 20 minutes ago, Ileana_Saphira said: ViridianCrown I did something wrong... I did something wrong... I even changed the player to the character name, for some reason an error appears... Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664945 Share on other sites More sharing options...
Ileana_Saphira Posted September 13, 2023 Author Share Posted September 13, 2023 ViridianCrown same error... Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664955 Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Share Posted September 13, 2023 (edited) Interesting... Look inside your character's anim folder. Is there a .zip there named player_leap.zip? If not, then you'll have to insert this file into said folder, as this contains all the necessary animation data for leaping.player_leap.zip Edited September 13, 2023 by ViridianCrown Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664959 Share on other sites More sharing options...
Ileana_Saphira Posted September 13, 2023 Author Share Posted September 13, 2023 ViridianCrown Somehow I inserted it into the folder with the character animation and the error disappeared, but for some reason the character still doesn’t jump... by default I had two of them Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664965 Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Share Posted September 13, 2023 If you could link your character files as a .zip I could take a look at the code for you and attempt to fix it. Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664968 Share on other sites More sharing options...
Ileana_Saphira Posted September 13, 2023 Author Share Posted September 13, 2023 ViridianCrown charax (6).zip Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664971 Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Share Posted September 13, 2023 I think I've found the problem. Where I wrote the phrase "CHARACTER_NAME" as a placeholder, I meant replacing the entire phrase, not just the "NAME" component. you the code was searching incorrectly for a character named "CHARACTER_CHARAX" when the name it should be searching for is "charax". I'm sending back the files with the fixed phrase. Hope it works this time! prefab.zip Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664974 Share on other sites More sharing options...
Ileana_Saphira Posted September 13, 2023 Author Share Posted September 13, 2023 ViridianCrown now I don't understand why the jump isn't showing, it's missing... Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664977 Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Share Posted September 13, 2023 You have to change the character's tag in the common_postinit as well as that's still listed as "CHARACTER_CHARAX" instead of "charax". Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664978 Share on other sites More sharing options...
Ileana_Saphira Posted September 13, 2023 Author Share Posted September 13, 2023 (edited) ViridianCrown I changed it, it appeared, but the problem is the same, it doesn’t jump... and excuse me, I probably don’t understand something, because I’m sleepy... Edited September 13, 2023 by Ileana_Saphira Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664983 Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Share Posted September 13, 2023 If you could send me all the character files (including animations and images so I can test in-game), I could take a look for you at everything and see if there's any problems pertaining to file placement or missing files I could replace. I can send it back once I'm done and could maybe have it done by the time you wake up. Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664986 Share on other sites More sharing options...
Ileana_Saphira Posted September 13, 2023 Author Share Posted September 13, 2023 (edited) ViridianCrown I hope I can trust you with it but I'm a little afraid to post this I’m just afraid that someone will misappropriate this, although I haven’t encountered this yet Edited September 14, 2023 by Ileana_Saphira Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664987 Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Share Posted September 13, 2023 (edited) Good news! I looked over the code, tweaked some parts, added some missing bits and now he leaps! I'll send over the file now, just know that I'll be editing my messages to remove all the links so that nobody else can misuse them as you're worried about. Just respond to this telling me you've received it and I'll take down the download link. The problem appeared to be that certain GLOBAL. parts weren't specified: local require = GLOBAL.require local STRINGS = GLOBAL.STRINGS local Recipe = GLOBAL.Recipe local RECIPETABS = GLOBAL.RECIPETABS local TECH = GLOBAL.TECH With these added, the code functions as intended. Best of luck with the character! Great character art, by the way! Edited September 14, 2023 by ViridianCrown Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1664997 Share on other sites More sharing options...
Ileana_Saphira Posted September 14, 2023 Author Share Posted September 14, 2023 (edited) ViridianCrown hee thank you very much! for your help and I’m even glad that you liked my Art :3 and I'm even glad that I can trust you and he jumps! Hooray!!! (◕ヮ◕ ) Edited September 14, 2023 by Ileana_Saphira Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1665011 Share on other sites More sharing options...
RexySeven Posted August 31, 2024 Share Posted August 31, 2024 On 9/14/2023 at 2:47 AM, ViridianCrown said: Good news! I looked over the code, tweaked some parts, added some missing bits and now he leaps! I'll send over the file now, just know that I'll be editing my messages to remove all the links so that nobody else can misuse them as you're worried about. Just respond to this telling me you've received it and I'll take down the download link. The problem appeared to be that certain GLOBAL. parts weren't specified: local require = GLOBAL.require local STRINGS = GLOBAL.STRINGS local Recipe = GLOBAL.Recipe local RECIPETABS = GLOBAL.RECIPETABS local TECH = GLOBAL.TECH With these added, the code functions as intended. Best of luck with the character! Great character art, by the way! Sorry for reviving old thread, but how to change amount of hunger taken away when jumping? Whatever I do it's taking away only 1 hunger point And also this code crashes when equipping lazy explorer: [string "scripts/componentactions.lua"]:2632: attempt to index a nil value LUA ERROR stack traceback: scripts/componentactions.lua:2632 in (method) UnregisterComponentActions (Lua) <2617-2644> scripts/entityscript.lua:655 in (method) RemoveComponent (Lua) <642-657> scripts/components/aoetargeting.lua:107 in (method) StopTargeting (Lua) <105-112> scripts/components/playercontroller.lua:241 in (local) fn (Lua) <229-258> scripts/entityscript.lua:1208 in (method) PushEvent (Lua) <1195-1222> scripts/prefabs/inventory_classified.lua:423 in (field) fn (Lua) <416-427> scripts/scheduler.lua:186 in (method) OnTick (Lua) <164-216> scripts/scheduler.lua:419 in (global) RunStaticScheduler (Lua) <417-425> scripts/update.lua:178 in () ? (Lua) <169-220> Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1745124 Share on other sites More sharing options...
RozeMeteor Posted September 21, 2024 Share Posted September 21, 2024 On 8/31/2024 at 9:42 AM, RexySeven said: Sorry for reviving old thread, but how to change amount of hunger taken away when jumping? Whatever I do it's taking away only 1 hunger point And also this code crashes when equipping lazy explorer: [string "scripts/componentactions.lua"]:2632: attempt to index a nil value LUA ERROR stack traceback: scripts/componentactions.lua:2632 in (method) UnregisterComponentActions (Lua) <2617-2644> scripts/entityscript.lua:655 in (method) RemoveComponent (Lua) <642-657> scripts/components/aoetargeting.lua:107 in (method) StopTargeting (Lua) <105-112> scripts/components/playercontroller.lua:241 in (local) fn (Lua) <229-258> scripts/entityscript.lua:1208 in (method) PushEvent (Lua) <1195-1222> scripts/prefabs/inventory_classified.lua:423 in (field) fn (Lua) <416-427> scripts/scheduler.lua:186 in (method) OnTick (Lua) <164-216> scripts/scheduler.lua:419 in (global) RunStaticScheduler (Lua) <417-425> scripts/update.lua:178 in () ? (Lua) <169-220> I'm not a modder myself but maybe you can try look through the Whisky mod, She got the ability to leap in the cost of hunger and it's a fairly recent mod. Link to comment https://forums.kleientertainment.com/forums/topic/150910-how-to-add-the-ability-for-a-character-to-fly/#findComment-1749811 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now