Jump to content

Andy90

Members
  • Posts

    189
  • Joined

  • Last visited

Everything posted by Andy90

  1. I collaborated with ChatGPT to create a 'lookat' function. While it's not a direct 'forward' function, I believe it can be helpful to others. function LookAt(position, pitch, yaw, distance) pitch = math.rad(pitch) yaw = math.rad(yaw) local forward = Vec3() forward.x = math.cos(pitch) * math.sin(yaw) forward.y = -math.sin(pitch) forward.z = math.cos(pitch) * math.cos(yaw) local forward_length = math.sqrt(forward.x ^ 2 + forward.y ^ 2 + forward.z ^ 2) forward.x = forward.x / forward_length forward.y = forward.y / forward_length forward.z = forward.z / forward_length forward.x = forward.x * distance + position.x forward.y = forward.y * distance + position.y forward.z = forward.z * distance + position.z return forward end
  2. I told within the dev diary that i will create a own holiday camp for the game and there we go, the first building for the camp is done
  3. Found it but i got a question. Its not that important but atm the object structure looks like this is there a method to include the collisionhull into the model itself ?
  4. Hello, I would like to ask if it's possible to create physics for an entity using Blender, for instance by naming an object "physics" or something similar?
  5. I've developed a second iteration of the script, this time utilizing a prefab. This means there are now two scripts in play: the Spawn Manager and the tree itself. 1. Spawn Manager Script.terrain = nil Script.player = nil --Entity "Player" Script.playerDistance = 30 --Float "Player Distance" Script.seed = 123456 --Float "Seed" Script.treeCount = 25 --Int "Trees" Script.minDist = 25 --Float "Min Distance" Script.maxDist = 75 --Float "Max Distance" Script.tree = "" --Path "Model" Script.treeMinHeight = 0.5 --Float "Min height" Script.treeMaxHeight = 1.0 --Float "Max height" Script.aabbCheck = false --Bool "AABB Check" Script.debug = true --Bool "Debug Mode" Script.treeData = {} function Script:Start() self.entity:Hide() --Find the terrain local world = World:GetCurrent() for i = 0, world:CountEntities() - 1 do local entity = world:GetEntity(i) if entity:GetClass() == Object.TerrainClass then self.terrain = tolua.cast(entity, "Terrain") end end local treeData = {} --Creates the tree data for the pivot tree local x = self.entity:GetPosition(true).x local z = self.entity:GetPosition(true).z local y = self.terrain:GetElevation(x, z) local treeInfo = { TreeName = self.entity:GetKeyValue("name") .. "_tree_center", TreeX = x, TreeY = y, TreeZ = z, TreeScale = 1.0, Visible = true, HideTime = 0 } table.insert(treeData, treeInfo) --Place a sphere at the pivot location if self.debug then local spehre = Model:Sphere() spehre:SetColor(1.0, 0.0, 0.0) spehre:SetScale(1.0) spehre:SetPosition(x, y, z) end math.randomseed(self.seed) for i = 0, self.treeCount do --Calculate the angle and the distance for the new tree local deg = 360 / self.treeCount * i local radians = math.rad(deg) local distance = math.random(self.minDist, self.maxDist) local sin = math.sin(radians) local cos = math.cos(radians) --Calculate the x,y,z cords for the tree local x = self.entity:GetPosition(true).x + distance * cos local z = self.entity:GetPosition(true).z + distance * sin local y = self.terrain:GetElevation(x, z) --Calculates the scale for the tree local scale = math.random(self.treeMinHeight * 100, self.treeMaxHeight * 100) / 100 --If AABB Check is enabled check for collision if self.aabbCheck then for _,item in pairs(self.treeData) do if Vec3(item.TreeX, item.TreeY, item.TreeZ):DistanceToPoint(Vec3(x,y,z)) < 0.5 then System:Print("Double Point") goto continue end end for i = 0, world:CountEntities() - 1 do local entity = world:GetEntity(i) if entity:GetClass() == Object.ModelClass and entity:GetParent() == nil then if entity:GetAABB():IntersectsPoint(Vec3(x,y,z), 1) then System:Print("intersect with entity " .. entity:GetKeyValue("name")) goto continue end end end end --Adds the tree info into the table local treeInfo = { TreeName = self.entity:GetKeyValue("name") .. "_tree_" .. i, TreeX = x, TreeY = y, TreeZ = z, TreeScale = scale, Visible = true, HideTime = 0 } table.insert(treeData, treeInfo) ::continue:: end self.treeData = treeData; end function Script:UpdateWorld() --Enables the trees when the player is nearby local distance = self.entity:GetDistance(self.player) if distance > self.playerDistance + self.maxDist and not self.entity:Hidden() then self.entity:Hide() self:HideTrees() elseif distance < self.playerDistance + self.maxDist and self.entity:Hidden() then self.entity:Show() self:ShowTrees() end -- System:Print(self.entity:GetKeyValue("name") .. " Children " .. self.entity:CountChildren() .. " / " .. #self.treeData) end function Script:ShowTrees() System:Print("Show Trees!") for _, item in pairs(self.treeData) do local tree = Prefab:Load(self.tree) tree.script.treeData = item tree:SetPosition(item.TreeX, item.TreeY, item.TreeZ) tree:SetScale(item.TreeScale) tree:SetKeyValue("name", item.TreeName) tree:SetParent(self.entity) if not item.Visible then tree:Hide() end end end function Script:HideTrees() local t = self.entity:CountChildren() for i = 0, self.entity:CountChildren() -1 do local child = self.entity:GetChild(i) child:Release() end end 2. Tree Script Script.treeData = nil Script.respawn = 10 * 60000 function Script:UpdateWorld() if self.entity:Hidden() then local now = Time:GetCurrent() if now > self.treeData.HideTime + self.respawn then self.treeData.Visible = true self.entity:Show() end end end function Script:Collision(entity, position, normal, speed) if entity:GetKeyValue("name") == "player" then if Window:GetCurrent():KeyDown(Key.E) then self.entity:Hide() self.treeData.Visible = false self.treeData.HideTime = Time:GetCurrent() end end end As you can see, the trees are no longer created within the Start function. They are dynamically generated when the player is nearby and released when the player moves away. This enhancement greatly improves performance. For example, if you have 10 spawners each with 50 trees, the old script would add 500 entities to the scene. With the new script, you only add the 10 pivot points, and create the entities for the trees only when the player is nearby. I hope this will help anyone within the future
  6. Ah okey this sounds very nice. I finished my script for a tree spawning based on a pivot Script.terrain = nil Script.player = nil --Entity "Player" Script.playerDistance = 30 --Float "Player Distance" Script.seed = 123456 --Float "Seed" Script.treeCount = 25 --Int "Trees" Script.minDist = 25 --Float "Min Distance" Script.maxDist = 75 --Float "Max Distance" Script.tree = "" --Path "Model" Script.treeMinHeight = 0.5 --Float "Min height" Script.treeMaxHeight = 1.0 --Float "Max height" Script.debug = true --Bool "Debug Mode" function Script:Start() --Find the terrain local world = World:GetCurrent() for i = 0, world:CountEntities() - 1 do local entity = world:GetEntity(i) if entity:GetClass() == Object.TerrainClass then self.terrain = tolua.cast(entity, "Terrain") end end --Sets a tree at the pivot location local x = self.entity:GetPosition(true).x local z = self.entity:GetPosition(true).z local y = self.terrain:GetElevation(x, z) local tree = Model:Load(self.tree) tree:SetPosition(x, y, z) tree:SetParent(self.entity) --Place a sphere at the pivot location if self.debug then local spehre = Model:Sphere() spehre:SetColor(1.0, 0.0, 0.0) spehre:SetScale(1.0) spehre:SetPosition(x, y, z) end math.randomseed(self.seed) for i = 0, self.treeCount do --Calculate the angle and the distance for the new tree local deg = 360 / self.treeCount * i local radians = math.rad(deg) local distance = math.random(self.minDist, self.maxDist) local sin = math.sin(radians) local cos = math.cos(radians) --Calculate the x,y,z cords for the tree local x = self.entity:GetPosition(true).x + distance * cos local z = self.entity:GetPosition(true).z + distance * sin local y = self.terrain:GetElevation(x, z) --Calculates the scale for the tree local scale = math.random(self.treeMinHeight * 100, self.treeMaxHeight * 100) / 100 --Creates the tree within the scene local tree = Model:Load(self.tree) tree:SetPosition(x, y, z) tree:SetScale(scale) tree:SetParent(self.entity) --Creates a debug sphere at the tree location if self.debug then local spehre = Model:Sphere() spehre:SetColor(1.0, 1.0, 0.0) spehre:SetScale(1.0) spehre:SetPosition(x, y, z) end end end function Script:UpdateWorld() --Enables the trees when the player is nearby local distance = self.entity:GetDistance(self.player) if distance > self.playerDistance then self.entity:Hide() else self.entity:Show() end end
  7. Ah, okay. Thanks anyway. I'll give it a shot with C++. If that doesn't work, I'll have to explore alternative methods to add wood to the player's inventory. Perhaps by incorporating additional prefab trees placed around a pivot, similar to the suggestion by @Alienhead. ---- For example, will it be possible to access individual vegetation objects in the Ultra Engine?
  8. ok, so there is no way to get the position from the trees? I found within the article linked from @klepto2 something like this AABB aabb = world->aabb; std::vector<Mat4> instances; layer->GetInstancesInAABB(aabb, instances);
  9. Is there a documentation about the terrain class in lua?
  10. The new dev diary is online i also found a name for the project "Nuclear Frontiers" i think the name fits well. Here is the logo for it an you can watch the new dev diary here:
  11. Tomorrow the new dev diary will be available here is some sneek peek out of one building
  12. First Real House will included into the game today It as not easy to create because i was need to create some own materials for substance
  13. Im not sure anymore tbh. But i think it was the editor.
  14. I think it has something to do with the model. After I fixed the issue on the zombie model today, the hit registration on it is now perfect. It might be due to the surface size.
  15. Thanks for the anwesers. i will check this yeah i set a boolean variable to true within the method and set it to false within UpdatePhysics. So at the moment its working fine.
  16. Thank you, this is very helpful. I believe I've properly configured the parameters in my pick function to acquire the closest target. However, there's a chance I may have misunderstood something. self.cam:Pick(p.x, p.y, pickinfo, pickradius, true, Collision.Prop) ----- I also edited the model a bit because at some parts of the body was no hit registration. So i added some spheres and asign them an invisible hitbox material. Works great so far
  17. I got another problem with pick. It seems pick is ignoring animations. Without animation with the idle animation
  18. ah ok i dont know this. Its a nice feature
×
×
  • Create New...