Files
MovementTests/systems/head/HeadSystem.cs
Minimata 27130257c9
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 18s
Create tag and build when new code gets to main / Export (push) Successful in 6m0s
small camera animation on mantle
2025-11-11 11:38:49 +01:00

52 lines
1.6 KiB
C#

using System;
using Godot;
namespace Movementtests.systems;
public partial class HeadSystem : Node3D
{
private Camera3D _camera;
private Marker3D _cameraAnchor;
private AnimationPlayer _animationPlayer;
[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");
_cameraAnchor = GetNode<Marker3D>("CameraAnchor");
_animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
}
public void OnMantle()
{
_animationPlayer.Play("mantle");
}
public void LookAround(Vector2 lookDir, float sensitivitMultiplier = 1f)
{
// Horizontal movement of head
float angleForHorizontalRotation = lookDir.X * LookSensitivity * sensitivitMultiplier;
RotateY(angleForHorizontalRotation);
// Vertical movement of head
Vector3 currentCameraRotation = _cameraAnchor.Rotation;
currentCameraRotation.X += Convert.ToSingle(lookDir.Y * LookSensitivity * sensitivitMultiplier);
currentCameraRotation.X = Mathf.Clamp(currentCameraRotation.X, Mathf.DegToRad(-90f), Mathf.DegToRad(90f));
_cameraAnchor.Rotation = currentCameraRotation;
_camera.GlobalTransform = _cameraAnchor.GetGlobalTransformInterpolated();
}
public Vector3 GetForwardHorizontalVector()
{
return GetGlobalTransform().Basis.Z;
}
public void SetHeight(float height)
{
Position = new Vector3(Position.X, height, Position.Z);
}
}