About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Game.World.hmHeight always returns 0
Author Message
Ozmodian Offline
Member

Post: #1
Game.World.hmHeight always returns 0
Hi all,

I am completely out of ideas. Everything i do in any sample code, Game.World.hmHeight always returns zero.

The most basic example I can show it in 14 - Game Basics -> 03 - World with Character . I added the following lines just before the updateItems(); call in virtual bool update()

Code:
if( Kb.b(KB_Z))
      {
         Vec2 pos_test = Players[0].pos().xz();
         Flt another_test = Game.World.hmHeight(pos_test) ;
         Log(S+ pos_test + " - " +another_test+ "\n");
      }


When you go to the logs, the position all looks good but he hmHeight is ALWAYS zero. I am sure i am missing something basic but i have tried like 4 tutorials and they all have the same results.

Any help is appreciated.
04-06-2013 11:07 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Game.World.hmHeight always returns 0
Hello,

The hmHeight functionality for 2.0 was added since Feb 28th 2013, please make a small change to terrain heightmap height, and it will be resaved with correct height.

Sorry for the inconvinience, I'll do this for worlds in the tutorials for next release.
04-07-2013 10:52 AM
Find all posts by this user Quote this message in a reply
Ozmodian Offline
Member

Post: #3
RE: Game.World.hmHeight always returns 0
Hi Esenthel,

Ahhh that explains it. I did not even think of that, but yes, that fixed it in the tutorials. How do the character controllers see the HM then if it is not loaded in correctly; the character is not walking through the terrain?

Actually, my real problem was not the tutorials, I just used those to see I I had the right approach or not. I created a brand new world and loaded it in with

Code:
Game.World.New(WorldID);

from there i was trying to use Game.World.hmHeight but always getting 0.000.

I tried everything to be able to get the height at a point, with no success. At what point does the HM get initialized? I am doing this all at the init() phase of Main.

Here are some of the things i tried

Setting the area states manually to every state possible with

Code:
Game.World.mode(Game.WORLD_MANUAL);
Memc<Game.WorldManager.AreaState> areastates;
     areastates.New().set(a, Game.AREA_ACTIVE);
     Game.World.areaSetState(areastates);
     Game.Area* the_area = Game.World.areaActive(a);

I tried getting the actual HM from the area, but this crashed

Code:
the_area.data().height().pixel(hx, hy)

At first I though that my world was not loaded correctly but things like the_area.state() and Game.world.areaSize() and Game.World.areaActive(a) all seem to return the correct results. I just can't get the hmHeight for some reason.

Thanks again for your quick response and any additional insight you or anybody else has would be awesome!


**EDIT**
Also, i just tried the_area.getData().height().is() and it returned false so it does seem like the HM has not been loaded. Not sure when that happens though or how to force it. Essentially, i am just trying to read the HM data from the world I created in the editor. Maybe there is an easier way to do that then all the ways I have tried above.
(This post was last modified: 04-07-2013 12:49 PM by Ozmodian.)
04-07-2013 12:28 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Game.World.hmHeight always returns 0
Hi,

Quote:How do the character controllers see the HM then if it is not loaded in correctly; the character is not walking through the terrain?
they operate on physics and not on hmHeight

Could you tell me if you did make a small change to terrain height for each area of your world before trying your codes again?

Your code for loading area is correct, but please remember that the_area or the_area.data can return NULL.
04-07-2013 12:59 PM
Find all posts by this user Quote this message in a reply
Ozmodian Offline
Member

Post: #5
RE: Game.World.hmHeight always returns 0
Hi Esenthel,

I made the world from scratch today so there is no problem there. It is just a simple world with no objects or anything, just terrain.

I know that area.data can be null, I tried using that and getData() but as you can see, it keeps saying my area.data.height returns and is() value of 0.

I guess my question is. Given a world, what is the best way to get at the height information of each area? I feel like the below should do it but as you can see the height.is() is 0 and Game:World.hmHeight(a) also returns 0.

Code:
Game.World.New(WorldID);
   Game.World.mode(Game.WORLD_MANUAL);
   Vec2  the_res = Game.World.worldToArea(Vec2(-215, -190));
   Log(S+the_res+"\n");  

      VecI2 a(-4, -3);
     Memc<Game.WorldManager.AreaState> areastates;
     areastates.New().set(a, Game.AREA_LOAD);
     Game.World.areaSetState(areastates);
     Game.Area* the_area = Game.World.areaLoaded(a);
  
      Log(S+"Valid="+the_area.getData().height().is());
      Log(S+Game.World.hmHeight(Vec2(-215, -190)));

Output is
-4, -3
Valid=0
0.000
04-07-2013 01:33 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Game.World.hmHeight always returns 0
Hi,

Perhaps you're accessing an area that doesn't have a terrain heightmap?

I've just tested your code on brand new world with heightmap placed, and it has height ok.

Oh, I think I know the problem, please call World.mode before World.New, because mode can't be dynamically switched when a world is already loaded, it first deletes the current world, and then changes the mode.

I'll update comments to the 'mode' method to include that
04-07-2013 01:56 PM
Find all posts by this user Quote this message in a reply
Ozmodian Offline
Member

Post: #7
RE: Game.World.hmHeight always returns 0
Esenthel Wrote:Oh, I think I know the problem, please call World.mode before World.New, because mode can't be dynamically switched when a world is already loaded, it first deletes the current world, and then changes the mode.

You are my hero. That did it!!! I can't believe i wasted ALLLLLL that time on something so stupid. I really really appreciate the help. I would have never thought that was the issue.

And yes, I would certainly recommend adding a comment to World.mode that it deletes the currently loaded world, that is very good to know.
04-07-2013 02:05 PM
Find all posts by this user Quote this message in a reply
Post Reply