From a9f4459e639e6297b2f7fc89b272cf349b10039b Mon Sep 17 00:00:00 2001 From: Robear Selwans Date: Wed, 9 Jun 2021 19:51:03 +0200 Subject: [PATCH] Added better control to the MainScene's camera Signed-off-by: Robear Selwans --- res/project/res/scripts/MainScene/Camera.lua | 12 +++++++----- res/project/res/scripts/MainScene/CameraHelper.lua | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/res/project/res/scripts/MainScene/Camera.lua b/res/project/res/scripts/MainScene/Camera.lua index 33dc1b6..55ef3f8 100644 --- a/res/project/res/scripts/MainScene/Camera.lua +++ b/res/project/res/scripts/MainScene/Camera.lua @@ -9,22 +9,24 @@ this.on_update = function() local deltaMouseMovement = Input.getDeltaMousePos() this.angles.y = this.angles.y - deltaMouseMovement.x * this.mouse_sens this.eulerAngles = this.angles - print('Camera OnUpdate') if Input.getKeyJustPressed(Input.KeyCode.Enter) then gotoScene('SideScene') end + local pos = this.position if Input.getKeyDown(Input.KeyCode.Up) then - this.position = this.position + this:getChild('RotationHelper').forward * this.speed + pos = pos + this:getChild('RotationHelper').forward * this.speed end if Input.getKeyDown(Input.KeyCode.Down) then - this.position = this.position - this:getChild('RotationHelper').forward * this.speed + pos = pos - this:getChild('RotationHelper').forward * this.speed end if Input.getKeyDown(Input.KeyCode.Right) then - this.position = this.position + Vec3:new(1, 0, 0) * this.speed + pos = pos + this:getChild('RotationHelper').right * this.speed end if Input.getKeyDown(Input.KeyCode.Left) then - this.position = this.position - Vec3:new(1, 0, 0) * this.speed + pos = pos - this:getChild('RotationHelper').right * this.speed end + + this.position = pos end diff --git a/res/project/res/scripts/MainScene/CameraHelper.lua b/res/project/res/scripts/MainScene/CameraHelper.lua index b08f677..41266f0 100644 --- a/res/project/res/scripts/MainScene/CameraHelper.lua +++ b/res/project/res/scripts/MainScene/CameraHelper.lua @@ -7,5 +7,4 @@ this.on_update = function() local deltaMouseMovement = Input.getDeltaMousePos() this.angles.x = this.angles.x - deltaMouseMovement.y * this.mouse_sens this.eulerAngles = this.angles - print('CameraHelper OnUpdate') end