Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Erarnitox

Place Buildings on Terrain

Question

hey i wrote this code to place Buildings on my Terrain but the code seems to take for ever or ends up with an array index error. i hope you can help me :)

Please login or register to see this code.

-the variable size is just terraindata.alphamapheight

-Terrains[] is an Array with all Terrains in the scene in it (so Terrains is just a simple Terrain)

-TerrainPosX is the global x position of the terrain in worldspace

-TerrainPosZ is the same for Z 

 

Got really stuck on this one :/ 

Thanks for your help ... if you do need more context please let me know and ill be happy to provide it... i just wanted to keep the snipped short n simple (still hope that im just too dumb to spot something obvious) 

 

 

Edited by Erarnitox

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 2

Make sure that heightmap is the size of the terrain (heightMap[terrainWidth, terrainHeight]). In addition, just to make the error isn't going to happen to mess it up on the sides, when you say heightMap[x,y] = posy; enclose it in an if statement saying if(x >= 0 && x < terrainWidth && y >= 0 && y < terrainHeight) that way if you place near the edge of the terrain it won't throw the error as well

  • Like 1

Share this post


Link to post
Share on other sites

  • 1

Your for(int y.. loop is saying x < instead of y <. Could be the culprit of how long it takes as well as your error

  • Like 1

Share this post


Link to post
Share on other sites
  • 1

Shouldn't those be a + 3 not a - 3? Because your loop is using + 3 but your check is using - 3

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

thank you :) i was literally watching this code for about 1h and didnt see this lol 

edit: still got the same problem tho. 

Edited by Erarnitox

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

it should already be that size but ill double check that later.

and for the edges i have this if statement: (which should do the same job (posx-terrainPox should be posxterrainPosx-1 if you want to be exact)) 

Please login or register to see this code. Edited by Erarnitox

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

nah thats fine ... at least to my understanding.... it should check if its too close to the lower edge, so even if it was +3 instead of -3 it would just deny the execution of some valid cases so even if i got that wrong there shouldnt be a problem ... so well i have some time now i guess i will go through this step by step again ^^ 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...