etoreo
New Member
http://u3d.as/5QL
Posts: 23
|
Post by etoreo on Mar 31, 2015 5:45:25 GMT
I need the real world height for an (x, z) point on the terrain. Is there a way to query Honey for this information?
|
|
etoreo
New Member
http://u3d.as/5QL
Posts: 23
|
Post by etoreo on Mar 31, 2015 22:28:44 GMT
I still need a way to get the world height of the Honey mesh/terrain for any given world point. Any help?
|
|
etoreo
New Member
http://u3d.as/5QL
Posts: 23
|
Post by etoreo on Apr 1, 2015 1:26:54 GMT
This is the best I could come up with looking at how foreground sprites are placed. It does not work, and prints errors but I think it is the correct method. Any chance you could correct the code or offer your own solution?
public static float terrainHeight(Vector3 pos)
{
HoneyFramework.Chunk c = HoneyFramework.Chunk.WorldToChunk(pos);
if(c == null)
{
Debug.LogError("Could not find height from pos: ");
Debug.LogError(pos);
return 0;
}
Vector2 uv = c.GetWorldToUV(pos);
if (uv.x > 0.0f && uv.x <= 1.0f && uv.y > 0.0f && uv.y <= 1.0f)
{
HoneyFramework.Vector2i textureUV = new HoneyFramework.Vector2i((int)((1 - uv.x) * c.height.width), (int)((1 - uv.y) * c.height.height));
Color heightColor = c.height.GetPixel(textureUV.x, textureUV.y);
//if (heightColor.a > 0.495f && heightColor.a < 0.75f)
{
return (heightColor.a - 0.5f) * 2f - 0.02f;
}
}
Debug.LogError("Could not find height from pos: ");
Debug.LogError(pos);
return 0;
}
|
|
|
Post by khash on Apr 1, 2015 10:43:48 GMT
You can try World class "GetWorldHeightAt"
|
|
etoreo
New Member
http://u3d.as/5QL
Posts: 23
|
Post by etoreo on Apr 1, 2015 22:41:57 GMT
I can't believe I missed that. Thank you. But after trying to use it, I don't think it works... I am trying to place some prefabs on Hex tiles and put them in the center of the tile, but at the correct height (especially important for mountains). If the tile was 100% flat, you should only be able to see the top half of the sphere, but as you can see from the screen shot the height being returned is a little off (I think its always too high, never too low). The grey sphere is not even touching the terrain (it should nestled in that hill). The pink sphere in the distance is kinda hovering above where it should be. public static bool placeResourceOnHex(HoneyFramework.Hex h, Resource.Type type)
{
if(type == Resource.Type.NONE || !HexHelper.canPlaceResourceOnHex (h, type))
return false;
GameObject prefab = Instantiate(Resources.Load("Prefabs/ResourceTypes/" + type.ToString())) as GameObject;
Vector3 pos = HoneyFramework.HexCoordinates.HexToWorld3D(h.position);
// THIS DOES NOT SEEM TO BE WORKING pos.y = HoneyFramework.World.GetWorldHeightAt(h.position);
prefab.transform.position = pos;
bool removedForgroundObject = false;
for(int i = 0; i < h.foregroundData.Count; i++)
{
HoneyFramework.ForegroundData fgd = h.foregroundData[i];
if (prefab.GetComponent<SphereCollider> ().bounds.Contains (fgd.position))
{
h.foregroundData.Remove(fgd);
i--; // adjust for removal
removedForgroundObject = true;
}
}
return removedForgroundObject;
} Is there a bug in your World.GetWorldHeightAt function, or am I using it incorrectly?
|
|
etoreo
New Member
http://u3d.as/5QL
Posts: 23
|
Post by etoreo on Apr 2, 2015 16:54:24 GMT
I need help on this or I will be unable to use your asset. 3 major components of my game rely on being able to place 3D objects on the terrain...
|
|
|
Post by khash on Apr 2, 2015 22:39:41 GMT
I haven't seen this issue anywhere but i will check it during this moth dev.
|
|
etoreo
New Member
http://u3d.as/5QL
Posts: 23
|
Post by etoreo on Apr 3, 2015 5:12:50 GMT
I found my bug. The line that asks Honey for the height was passing the hex's 3i position, not world position.
Changing it to:
Vector3 pos = HoneyFramework.HexCoordinates.HexToWorld3D(pos); Works like a charm.
|
|
|
Post by khash on Apr 3, 2015 9:37:34 GMT
Great
|
|