Camera now properly moving with player again.

WorldChunkRefactoring
Martin Felis 2023-02-12 16:55:30 +01:00
parent 70724899ad
commit 48f7081134
1 changed files with 10 additions and 2 deletions

View File

@ -25,6 +25,7 @@ public class Game : Spatial
private Player _player;
private Chest _chest;
private TileWorld _tileWorld;
private Camera _camera;
// Resources
private PackedScene _tileHighlightScene;
@ -34,6 +35,7 @@ public class Game : Spatial
private HexCell _lastTile;
private HexCell _currentTile;
private Vector2 _currentTileOffset;
private Vector3 _cameraOffset;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@ -58,6 +60,8 @@ public class Game : Spatial
_player = GetNode<Player>("Player");
_chest = GetNode<Chest>("Entities/Chest");
_tileWorld = GetNode<TileWorld>("TileWorld");
_camera = GetNode<Camera>("Camera");
_cameraOffset = _camera.GlobalTranslation - _player.GlobalTranslation;
Debug.Assert(_tileWorld != null);
@ -135,6 +139,7 @@ public class Game : Spatial
}
public override void _Process(float delta)
{
_framesPerSecondLabel.Text = Engine.GetFramesPerSecond().ToString();
@ -156,8 +161,11 @@ public class Game : Spatial
_numCoordsAddedLabel.Text = _streamContainer.AddedCoords.Count.ToString();
_numCoordsRemovedLabel.Text = _streamContainer.RemovedCoords.Count.ToString();
}
}
Transform cameraTransform = _camera.Transform;
cameraTransform.origin = _player.GlobalTranslation + _cameraOffset;
_camera.Transform = cameraTransform;
}
public void OnAreaInputEvent(Node camera, InputEvent inputEvent, Vector3 position, Vector3 normal,
int shapeIndex)