Skip to content

Commit

Permalink
camera movement forward/backward based on mouse wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed Dec 2, 2023
1 parent 89a5994 commit 2f3e47f
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using UnityEngine;

namespace UniRecast.Runtime
Expand All @@ -25,6 +24,8 @@ public class UniRcCamera : MonoBehaviour
private float _moveDown;
private float _moveAccel;

private float _scrollZoom;

private void Update()
{
UpdateMouse(Time.deltaTime);
Expand Down Expand Up @@ -60,6 +61,17 @@ private void UpdateMouse(float dt)
if (Input.GetMouseButton(2))
{
}

// wheel scroll
var scrollDelta = Input.mouseScrollDelta;
if (0 != scrollDelta.y)
{
_scrollZoom = Mathf.Clamp(scrollDelta.y, -1, 1);
}
else
{
_scrollZoom = 0;
}
}

private float GetKeyValue(KeyCode key1, KeyCode key2)
Expand Down Expand Up @@ -94,8 +106,6 @@ private void UpdateKeyboard(float dt)

private void UpdateCamera(float dt)
{
float scrollZoom = 0;

float keySpeed = 22.0f;
if (0 < _moveAccel)
{
Expand All @@ -104,8 +114,7 @@ private void UpdateCamera(float dt)

float x = (_moveRight - _moveLeft) * keySpeed * dt;
float y = (_moveUp - _moveDown) * keySpeed * dt;
float z = (_moveFront - _moveBack) * keySpeed * dt + scrollZoom * 2.0f;
scrollZoom = 0;
float z = (_moveFront - _moveBack) * keySpeed * dt + _scrollZoom * 2.0f;

var forward = transform.forward;
var right = transform.right;
Expand Down

0 comments on commit 2f3e47f

Please sign in to comment.