39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System;
|
|
using Godot;
|
|
|
|
namespace DRPGActionGame.Player;
|
|
|
|
public partial class CameraController : Node3D {
|
|
[Export] private float sensitivity = 5f;
|
|
[Export] private SpringArm3D springArm3D;
|
|
|
|
private const float maxXRot = .25f;
|
|
private const float maxZoom = 2f;
|
|
private const float minZoom = 10f;
|
|
|
|
// public override void _Ready() => Input.MouseMode = Input.MouseModeEnum.Captured;
|
|
|
|
// public override void _Process(double delta) => GlobalPosition = GetParent<Node3D>().GlobalPosition;
|
|
|
|
public override void _Input(InputEvent @event) {
|
|
switch (@event) {
|
|
case InputEventMouseMotion inputEventMouseMotion: {
|
|
float xRot = Mathf.Clamp(Rotation.X - inputEventMouseMotion.Relative.Y / 1000 * sensitivity, -maxXRot, +maxXRot);
|
|
float yRot = Rotation.Y - inputEventMouseMotion.Relative.X / 1000 * sensitivity;
|
|
Rotation = new(xRot, yRot, 0);
|
|
break;
|
|
}
|
|
case InputEventMouseButton inputEventMouseButton: {
|
|
if (inputEventMouseButton.ButtonIndex == MouseButton.WheelDown) {
|
|
if (springArm3D.SpringLength < minZoom)
|
|
springArm3D.SpringLength += 0.1f;
|
|
}
|
|
else if (inputEventMouseButton.ButtonIndex == MouseButton.WheelUp) {
|
|
if (springArm3D.SpringLength > maxZoom)
|
|
springArm3D.SpringLength -= 0.1f;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |