Ground level now at height 0.

WorldChunkRefactoring
Martin Felis 2023-09-19 20:32:22 +02:00
parent 1e7e07f349
commit e91b64e82f
3 changed files with 12 additions and 9 deletions

View File

@ -269,7 +269,6 @@ public class Game : Spatial
public void OnTileHovered(HexTile3D tile) public void OnTileHovered(HexTile3D tile)
{ {
Transform highlightTransform = tile.GlobalTransform; Transform highlightTransform = tile.GlobalTransform;
highlightTransform.origin.y += 0.1f;
_mouseTileHighlight.Transform = highlightTransform; _mouseTileHighlight.Transform = highlightTransform;
_mouseWorldLabel.Text = highlightTransform.origin.ToString(); _mouseWorldLabel.Text = highlightTransform.origin.ToString();
_mouseTileOffsetLabel.Text = tile.OffsetCoords.ToString(); _mouseTileOffsetLabel.Text = tile.OffsetCoords.ToString();

View File

@ -40,7 +40,7 @@ public class TileWorld : Spatial
[Export] public int Size = 64; [Export] public int Size = 64;
[Export] public bool DebugMap; [Export] public bool DebugMap;
public float HeightScale = 2.0f; public float HeightScale = 1.0f;
public Image HeightmapImage; public Image HeightmapImage;
public Image ColormapImage; public Image ColormapImage;
public Image NavigationmapImage; public Image NavigationmapImage;
@ -293,7 +293,7 @@ public class TileWorld : Spatial
Spatial assetInstance = (Spatial)assets[assetIndex].Duplicate(); Spatial assetInstance = (Spatial)assets[assetIndex].Duplicate();
Transform assetTransform = Transform.Identity; Transform assetTransform = Transform.Identity;
assetTransform.origin = GetHexCenterFromOffset(offsetCoord); assetTransform.origin = GetHexCenterFromOffset(offsetCoord);
assetTransform.origin.y += 1.2f; assetTransform.origin.y = GetHeightAtOffset(offsetCoord);
assetTransform.basis = assetTransform.basis =
assetTransform.basis.Rotated(Vector3.Up, (float)(randomGenerator.NextDouble() * Mathf.Pi * 2)); assetTransform.basis.Rotated(Vector3.Up, (float)(randomGenerator.NextDouble() * Mathf.Pi * 2));
assetInstance.Transform = assetTransform; assetInstance.Transform = assetTransform;
@ -364,7 +364,7 @@ public class TileWorld : Spatial
Chest chestAsset = (Chest)_chestScene.Instance(); Chest chestAsset = (Chest)_chestScene.Instance();
Transform assetTransform = Transform.Identity; Transform assetTransform = Transform.Identity;
assetTransform.origin = GetHexCenterFromOffset(offsetCoord); assetTransform.origin = GetHexCenterFromOffset(offsetCoord);
assetTransform.origin.y += 1.2f; assetTransform.origin.y = GetHeightAtOffset(offsetCoord);
chestAsset.Transform = assetTransform; chestAsset.Transform = assetTransform;
Entities.AddChild(chestAsset); Entities.AddChild(chestAsset);
MarkCellUnwalkable(cell); MarkCellUnwalkable(cell);
@ -461,14 +461,18 @@ public class TileWorld : Spatial
Vector2 textureCoord = OffsetToTextureCoord(offsetCoord); Vector2 textureCoord = OffsetToTextureCoord(offsetCoord);
float heightmapHeight = HeightmapImage.GetPixel((int)textureCoord.x, (int)(textureCoord.y)).r; float heightmapHeight = (HeightmapImage.GetPixel((int)textureCoord.x, (int)(textureCoord.y)).r - 0.5f) * HeightScale;
if (heightmapHeight > 0.5) if (heightmapHeight <= 0)
{ {
heightmapHeight = 0.6f; heightmapHeight -= 0.03f;
}
else
{
heightmapHeight = 0f;
} }
return heightmapHeight * HeightScale; return heightmapHeight;
} }

View File

@ -20,7 +20,7 @@ roughness = 0.0
[node name="TileHighlight" type="Spatial"] [node name="TileHighlight" type="Spatial"]
[node name="TileMesh" type="MeshInstance" parent="."] [node name="TileMesh" type="MeshInstance" parent="."]
transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, -0.05, 0 ) transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0 )
cast_shadow = 0 cast_shadow = 0
mesh = SubResource( 3 ) mesh = SubResource( 3 )
skeleton = NodePath("../..") skeleton = NodePath("../..")