Slimwaffle Posted August 29, 2018 Share Posted August 29, 2018 I am wondering what the correct way to use this Undocumented command is? I am trying to make digging scripts for my game. I will post the code here. If I use SetElevation I get an error saying argument 5 needs to be a boolean and if I use SetHeight nothing changes and the game crashes. Getting the elevation works fine setting it is the issue. I want to be able to raise and lower the ground in game. Quote --Digging Script if window:KeyHit(Key.PageUp) then local ELPOS = self.entity:GetPosition() raise = terrain:GetElevation(ELPOS.x,ELPOS.y) terrain:SetElevation(ELPOS.x,ELPOS.y, raise + 10) System:Print(raise) end Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted August 29, 2018 Share Posted August 29, 2018 In C++ the syntax is this; void SetElevation(const int x, const int y, const float elevation, const bool update); Try this; terrain:SetElevation(ELPOS.x,ELPOS.y, raise + 10, true) I'm not sure why it says argument 5... there's only 4 in C++. Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted August 29, 2018 Author Share Posted August 29, 2018 So doing this stopped the crashing but its still not changing the terrain elevation. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted August 29, 2018 Share Posted August 29, 2018 I remember trying this ages ago and that one of the functions to set height didn't work. Have you tried SetHeight() with the last argument as true? (In C++ it's false by default) terrain:SetHeight(ELPOS.x,ELPOS.y, raise + 10, true) Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted August 29, 2018 Author Share Posted August 29, 2018 Same thing again stops the crashing but doesn't actually change anything Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted August 29, 2018 Share Posted August 29, 2018 I'm not sure then sorry. Maybe it's something Josh can answer. I remember trying to get it to work but can't actually remember if I succeeded or not... Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted August 29, 2018 Author Share Posted August 29, 2018 Its all good thanks anyway mate. I will have to just wait. 1 Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 31, 2018 Share Posted August 31, 2018 The height value in SetHeight() is normalized from 0 to 1 where 1 is equal to the max altitude of the terrain. Altitude of the terrain is set by SetScale() via code or via the Editor terrain settings, so you would need to normalize the height you want in regards to the max altitude being equal to 1. Another thing to keep in mind: a terrain position is not the same as the world position. For example: on a 64m x 64m terrain, the world origin (0,0,0) would be located at X=32 & Z =32 on a flat terrain when using SetHeight(). Example showing SetHeight() in action: window = Window:Create("terrain example",0,0,800,600,Window.Titlebar+Window.Center) context = Context:Create(window) world = World:Create() camera = Camera:Create() camera:SetPosition(0,5,-5) camera:SetMultisampleMode(8) skybox = Texture:Load("Materials/Sky/skybox_texture.tex") camera:SetSkybox(skybox) light = DirectionalLight:Create() light:SetRotation(35,35,0) terrain = Terrain:Create(64,true) terrain:SetLayerTexture(0, Texture:Load("Materials/Developer/Bluegrid.tex"), 0) terrain:SetScale(1,100,1) ball = Model:Sphere(32) ballmat = Material:Load("Materials/Developer/Orangegrid.mat") ball:SetMaterial(ballmat) ball:SetScale(4,4,4) shape = Shape:Sphere(0,0,0, 0,0,0, 1,1,1) ball:SetShape(shape) shape:Release() ball:SetCollisionType(Collision.Prop) ball:SetSweptCollisionMode(true) ball:SetPosition(24,6,0) ball:SetMass(1) camera:Point(ball) while window:KeyDown(Key.Escape)==false do if window:Closed() then break end pos = ball:GetPosition(true) camera:SetPosition(pos.x,6,pos.z-10) camera:Point(ball) if terrain~=nil then for x = 0, 64 do local y = Time:Millisecs()/600 for z = 0, 64 do local height = math.sin(y+x) / 40 terrain:SetHeight(x,z,height) end end terrain:UpdateNormals() end Time:Update() world:Update() world:Render() context:Sync(true) end 1 1 2 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Slimwaffle Posted August 31, 2018 Author Share Posted August 31, 2018 Even if I simply use; terrain:SetScale(1,100,1) if window:KeyDown(key.PageUP) then terrain:SetHeight(512,512, 10) end Nothing Happens. On a 1024 x 1024 map this should be affecting 0,0. But there is no change. Even adding in; terrain:UpdateNormals() Time:Update() world:Update() world:Render() does nothing to help. Even if I system print the height for 0, 0 there is change but you can't physically see it in the world. Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 31, 2018 Share Posted August 31, 2018 Did you try my example? Does it work for you? You are not giving us enough information to determine if its something you are doing wrong or its a problem with LE. What version are you using? Give us a simple example to try. And again, the height value is on scale of 0 to 1. This simple example works for me: window = Window:Create("terrain example",0,0,800,600,Window.Titlebar+Window.Center) context = Context:Create(window) world = World:Create() camera = Camera:Create() camera:SetPosition(0,30,-30) camera:SetRotation(45,0,0) camera:SetMultisampleMode(8) light = DirectionalLight:Create() light:SetRotation(35,35,0) terrain = Terrain:Create(64,true) terrain:SetLayerTexture(0, Texture:Load("Materials/Developer/Bluegrid.tex"), 0) terrain:SetScale(1,10,1) math.randomseed(Time:Millisecs()) while window:KeyDown(Key.Escape)==false do if window:Closed() then break end if window:KeyHit(Key.Space) then terrain:SetHeight(math.random(0,64),math.random(0,64),1) terrain:UpdateNormals() end Time:Update() world:Update() world:Render() context:SetBlendMode(Blend.Alpha) context:DrawText("Press SPACE to raise a random terrain point",2,2) context:SetBlendMode(Blend.Solid) context:Sync(true) end 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Slimwaffle Posted August 31, 2018 Author Share Posted August 31, 2018 Sorry I will have a crack at this again later today and post my code here. Quote Link to comment Share on other sites More sharing options...
macklebee Posted September 3, 2018 Share Posted September 3, 2018 On 8/31/2018 at 6:11 PM, slimwaffle said: Sorry I will have a crack at this again later today and post my code here. slimwaffle - is this resolved or are you still having issues getting a terrain to deform? If so, post your example so we can try to replicate the issue. It's called being friendly. - macklebee 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Slimwaffle Posted September 3, 2018 Author Share Posted September 3, 2018 The only way I was able to make the code work an manipulate the terrain was with this ELPOS = self.entity:GetPosition() if window:KeyHit(Key.L) then raise = terrain:GetScale(true) terrain:SetScale(raise + 1) System:Print(raise) end But now I have to figure out how to rewrite it to do it only at my players location. And there is a bug that makes me fall through the map after terrain has be manipulated. But the only command that you can actually see the change happening is using terrain:SetScale() . Sorry for the lack of response. Been super busy prepping this project for release. Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted September 3, 2018 Author Share Posted September 3, 2018 GetHeight works when I system Print. SetHeight works when I system print. GetElevation works using system print. SetElevation work using system print. SetScale is the only one I can see that actually changes in game. However I could be wrong. Because I think that I might not be converting. the player:GetPosition() correctly for accessing terrain. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.