Jump to content

SetElevation


Slimwaffle
 Share

Recommended Posts

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

 

 

Link to comment
Share on other sites

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

 

  • Like 1
  • Thanks 1
  • Upvote 2

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

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.

Link to comment
Share on other sites

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

setheight.jpg.dd23da8ed930f5506510cd02d5eeb818.jpg

  • Like 1

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

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

  • Like 1

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

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...