gd: fixed look inputs
This commit is contained in:
30
systems/head/HeadSystem.cs
Normal file
30
systems/head/HeadSystem.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class HeadSystem : Node3D
|
||||
{
|
||||
private Camera3D _camera;
|
||||
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float LookSensitivity { get; set; } = 1f;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
Input.SetMouseMode(Input.MouseModeEnum.Captured);
|
||||
_camera = GetNode<Camera3D>("CameraSmooth/Camera3D");
|
||||
}
|
||||
|
||||
public void LookAround(Vector2 lookDir)
|
||||
{
|
||||
// Horizontal movement of head
|
||||
float angleForHorizontalRotation = lookDir.X * LookSensitivity;
|
||||
RotateY(angleForHorizontalRotation);
|
||||
|
||||
// Vertical movement of head
|
||||
Vector3 currentCameraRotation = _camera.Rotation;
|
||||
currentCameraRotation.X += Convert.ToSingle(lookDir.Y * LookSensitivity);
|
||||
currentCameraRotation.X = Mathf.Clamp(currentCameraRotation.X, Mathf.DegToRad(-90f), Mathf.DegToRad(90f));
|
||||
|
||||
_camera.Rotation = currentCameraRotation;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user