DingoLingo Posted June 10, 2024 Share Posted June 10, 2024 Just need a bit of help with the positioning of things I'm spawning from my component. I've had the idea to try making some kind of portable base, something the player can carry around and take through shards. Currently, I just search for entities, store them in a table, and remove them from the world. But when I spawn them back into the world, I can't figure out how to keep their spacing at the new location. So I just dump them into a single spot at the moment. I'm not really any good at math, so if anyone can help with that, it would be amazing! PocketInterior: Spoiler function PocketInterior:Recreate_Test() if next(self.interior_storage) ~= nil then --Currently the component owner. Swap this for a valid interior location eventually. local target_x,target_y,target_z = self.inst.Transform:GetWorldPosition() for i, v in ipairs(self.interior_storage) do --==Spawn==-- local spawned_object = SpawnSaveRecord(v) --==Reposition==-- local x,y,z = spawned_object.Transform:GetWorldPosition() --Math... Need to relocate to our target position, WITHOUT messing up our spawned_object'a spacing. x = x y = y z = z --Just dump all our stuff into a our target spot for now. Fix later. spawned_object.Transform:SetPosition(target_x, target_y, target_x) --==Print New Location==-- print("Spawned: -"..v.prefab.."- at location : X:"..target_x.." Y:"..target_y.." Z:"..target_z) end else print("We don't have anything to make our rebuild our interior!") end end Link to comment https://forums.kleientertainment.com/forums/topic/156826-positioning-help/ Share on other sites More sharing options...
_zwb Posted June 10, 2024 Share Posted June 10, 2024 Just save the relative position of objects to the Pocket Interior thing Link to comment https://forums.kleientertainment.com/forums/topic/156826-positioning-help/#findComment-1722380 Share on other sites More sharing options...
DingoLingo Posted June 10, 2024 Author Share Posted June 10, 2024 (edited) Alright. How though? I've tried making the spawned objects position relative to 0,0,0 by subtracting the component owner's position from the spawned objects, then adding the owner's position again to get the actual target position. But that wildly changes if I move around while carrying the item with my PocketInterior component. Spoiler function PocketInterior:Recreate_Test() --Cleaned it up a bit. if next(self.interior_storage) ~= nil then --Currently the component owner. Swap this for a valid interior location eventually. local target_pos = Vector3(self.inst.Transform:GetWorldPosition()) print(target_pos) for i, v in ipairs(self.interior_storage) do --==Spawn==-- local spawned_object = SpawnSaveRecord(v) --==Reposition==-- local object_pos = Vector3(spawned_object.Transform:GetWorldPosition()) local new_x = object_pos.x - target_pos.x local new_z = object_pos.z - target_pos.z spawned_object.Transform:SetPosition(new_x, object_pos.y, new_z) --==Print New Location==-- print("Spawned: -"..v.prefab.."- at location : X:"..new_x.." Y:"..target_pos.y.." Z:"..new_z) end else print("We don't have anything to make our rebuild our interior!") end end Edited June 10, 2024 by DingoLingo Forgot to add snippet. Link to comment https://forums.kleientertainment.com/forums/topic/156826-positioning-help/#findComment-1722484 Share on other sites More sharing options...
_zwb Posted June 10, 2024 Share Posted June 10, 2024 32 minutes ago, DingoLingo said: How though? I don't know without the full code. Link to comment https://forums.kleientertainment.com/forums/topic/156826-positioning-help/#findComment-1722498 Share on other sites More sharing options...
DingoLingo Posted June 10, 2024 Author Share Posted June 10, 2024 Oh, right! My bad. Spoiler local PocketInterior = Class(function(self, inst) self.inst = inst self.interior_storage = {} end) --===========================-- --==oO REMOVE / RECREATE Oo==-- --===========================-- function PocketInterior:Remove_Test() --==Clear Interior Storage==-- print("Forgetting current Interior...") self.interior_storage = {} --==Search for things to store==-- --Currently the component owner. Swap this for a valid interior location eventually. local x,y,z = self.inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 20, nil, { "player", "INLIMBO", "FX", "pocketinterior_item" }) for k,v in pairs(ents) do if v then --==Save and Remove==-- local stored_object = v:GetSaveRecord() table.insert(self.interior_storage, stored_object) v:Remove() end end end function PocketInterior:Recreate_Test() if next(self.interior_storage) ~= nil then --Currently the component owner. Swap this for a valid interior location eventually. local target_pos = Vector3(self.inst.Transform:GetWorldPosition()) print(target_pos) for i, v in ipairs(self.interior_storage) do --==Spawn==-- local spawned_object = SpawnSaveRecord(v) --==Reposition==-- local object_pos = Vector3(spawned_object.Transform:GetWorldPosition()) local new_x = object_pos.x - target_pos.x local new_z = object_pos.z - target_pos.z spawned_object.Transform:SetPosition(new_x, object_pos.y, new_z) --==Print New Location==-- print("Spawned: -"..v.prefab.."- at location : X:"..new_x.." Y:"..target_pos.y.." Z:"..new_z) end else print("We don't have anything to make our rebuild our interior!") end end --=====================-- --==oO SAVE / LOAD Oo==-- --=====================-- function PocketInterior:OnSave() return { interior_storage = self.interior_storage, } end function PocketInterior:OnLoad(data) if data ~= nil then self.interior_storage = data.interior_storage end end return PocketInterior Link to comment https://forums.kleientertainment.com/forums/topic/156826-positioning-help/#findComment-1722501 Share on other sites More sharing options...
_zwb Posted June 10, 2024 Share Posted June 10, 2024 (edited) --==Save and Remove==-- local stored_object = v:GetSaveRecord() -- stored_object.x/y/z is from v.Transform stored_object.relative_x = stored_object.x - x stored_object.relative_y = (stored_object.y or 0) - y stored_object.relative_z = stored_object.z - z table.insert(self.interior_storage, stored_object) v:Remove() --==Spawn==-- local spawned_object = SpawnSaveRecord(v) --==Reposition==-- local relative_x = v.relative_x local relative_y = v.relative_y local relative_z = v.relative_z spawned_object.Transform:SetPosition(relative_x + target_pos.x, relative_y + target_pos.y, relative_z + target_pos.z) Edited June 10, 2024 by _zwb Link to comment https://forums.kleientertainment.com/forums/topic/156826-positioning-help/#findComment-1722554 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