You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Camera;
|
|
|
|
public partial class CameraPivot : Node3D
|
|
{
|
|
[Export] private bool _canPitch;
|
|
[Export] private bool _canYaw;
|
|
[Export] private float _rotateSpeed = 0.003f;
|
|
[Export] private Node3D _subPivot;
|
|
|
|
public override void _Ready()
|
|
{
|
|
Input.MouseMode = Input.MouseModeEnum.Captured;
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if(@event.IsActionPressed("click"))
|
|
{
|
|
if (Input.MouseMode == Input.MouseModeEnum.Visible)
|
|
{
|
|
Input.MouseMode = Input.MouseModeEnum.Captured;
|
|
}
|
|
}
|
|
|
|
if (@event.IsActionPressed("ui_cancel"))
|
|
{
|
|
Input.MouseMode = Input.MouseModeEnum.Visible;
|
|
}
|
|
|
|
if (@event is InputEventMouseMotion test)
|
|
{
|
|
if (Input.MouseMode != Input.MouseModeEnum.Captured)
|
|
return;
|
|
|
|
if (_canYaw)
|
|
_subPivot.RotateX(test.Relative.Y * -_rotateSpeed);
|
|
if(_canPitch)
|
|
this.RotateY(test.Relative.X * -_rotateSpeed);
|
|
|
|
}
|
|
}
|
|
|
|
} |