From 48f7081134fffec85250d89bfa403a229701ab2b Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 12 Feb 2023 16:55:30 +0100 Subject: [PATCH] Camera now properly moving with player again. --- scenes/Game.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scenes/Game.cs b/scenes/Game.cs index 839e2f8..8efe7bf 100644 --- a/scenes/Game.cs +++ b/scenes/Game.cs @@ -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,7 +60,9 @@ public class Game : Spatial _player = GetNode("Player"); _chest = GetNode("Entities/Chest"); _tileWorld = GetNode("TileWorld"); - + _camera = GetNode("Camera"); + _cameraOffset = _camera.GlobalTranslation - _player.GlobalTranslation; + Debug.Assert(_tileWorld != null); // resources @@ -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)