gd: fixed look inputs

This commit is contained in:
2025-05-29 09:49:56 +02:00
parent 5104144ba3
commit c3e2c974ca
21 changed files with 348 additions and 558 deletions

View File

@ -140,7 +140,6 @@ public partial class HealthSystem : Node3D
private bool _dead;
private Node3D _head;
private AnimationPlayer _animationPlayer;
private ShaderMaterial _blurMaterial;
public struct HealthSystemInitParams
@ -148,7 +147,6 @@ public partial class HealthSystem : Node3D
public Gravity Gravity;
public CharacterBody3D Parent;
public Camera3D Camera;
public AnimationPlayer AnimationPlayer;
public Node3D Head;
public ColorRect VignetteRect;
public ColorRect DistortionRect;
@ -187,8 +185,6 @@ public partial class HealthSystem : Node3D
_blurMaterial.SetShaderParameter(Constants.BLUR_SHADER_LIMIT, 0.0f);
_blurMaterial.SetShaderParameter(Constants.BLUR_SHADER_BLUR, 0.0f);
_animationPlayer = initParams.AnimationPlayer;
}
public override void _Process(double delta)
@ -250,7 +246,6 @@ public partial class HealthSystem : Node3D
if (!_deathAnimationPlayed)
{
_animationPlayer.PlayCameraRotationOnDeath();
_deathAnimationPlayed = true;
}

View File

@ -1,58 +0,0 @@
using System;
using Godot;
using RustyOptions;
namespace PolarBears.PlayerControllerAddon;
public partial class MantleSystem: Node3D
{
[Export(PropertyHint.Range, "0,2,0.1,suffix:m,or_greater")]
public float MantleEndLocationDistanceFromWall { get; set; } = 1f;
[Export(PropertyHint.Range, "0,10,0.1,suffix:m,or_greater")]
public float MantleHeightCastStart { get; set; } = 2f;
[Export(PropertyHint.Range, "0,10,0.01,suffix:m,or_greater")]
public float MaxStepHeight = 0.5f;
private Node3D _head;
private ShapeCast3D _wallInFrontCast3D;
private ShapeCast3D _mantleCast3D;
private RayCast3D _mantleCheckCast3D;
public void Init(Node3D head)
{
_head = head;
_wallInFrontCast3D = GetNode<ShapeCast3D>("WallInFrontCast3D");
_mantleCast3D = GetNode<ShapeCast3D>("MantleCast3D");
}
public Option<Vector3> FindMantleInFrontOfPlayer()
{
_wallInFrontCast3D.SetRotation(new Vector3(
_wallInFrontCast3D.Rotation.X,
_head.Rotation.Y,
_wallInFrontCast3D.Rotation.Z));
if (!_wallInFrontCast3D.IsColliding())
{
return Option<Vector3>.None;
}
var collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0);
var collisionNormal = _wallInFrontCast3D.GetCollisionNormal(0);
return FindMantleLocationAtPoint(collisionPoint, collisionNormal);
}
public Option<Vector3> FindMantleLocationAtPoint(Vector3 point, Vector3 wallNormal)
{
var horizontalEndLocation = point - wallNormal * MantleEndLocationDistanceFromWall;
var shapeCastStartLocation = horizontalEndLocation + Vector3.Up * MantleHeightCastStart;
_mantleCast3D.SetGlobalPosition(shapeCastStartLocation);
var targetLocation = Vector3.Down * MantleHeightCastStart + Vector3.Up * MaxStepHeight;
_mantleCast3D.SetTargetPosition(targetLocation);
if (_mantleCast3D.IsColliding() && _mantleCast3D.GetCollisionNormal(0).Y > 0.9f)
return Option.Some(_mantleCast3D.GetCollisionPoint(0));
return Option<Vector3>.None;
}
}

View File

@ -1 +0,0 @@
uid://bja6tis1vaysu

View File

@ -8,8 +8,6 @@ public partial class Mouse : Node3D
[Export(PropertyHint.Range, "0,0.1,0.001,or_greater")]
public float Sensitivity { get; set; } = 0.004f;
private Node3D _head;
private Camera3D _camera;
@ -40,17 +38,4 @@ public partial class Mouse : Node3D
_camera.Rotation = currentCameraRotation;
}
public override void _UnhandledInput(InputEvent @event)
{
if (_isPlayerDead())
{
return;
}
if (@event is InputEventMouseMotion eventMouseMotion)
{
var lookDir = new Vector2(-eventMouseMotion.Relative.X, -eventMouseMotion.Relative.Y);
LookAround(lookDir);
}
}
}

View File

@ -8,7 +8,7 @@ namespace PolarBears.PlayerControllerAddon;
public partial class PlayerController : CharacterBody3D
{
// User API to important child nodes.
public Node3D Head;
public HeadSystem HeadSystem;
public Bobbing Bobbing;
public FieldOfView FieldOfView;
public Stamina Stamina;
@ -18,7 +18,7 @@ public partial class PlayerController : CharacterBody3D
public CapsuleCollider CapsuleCollider;
public Gravity Gravity;
public HealthSystem HealthSystem;
public Mouse Mouse;
[Export(PropertyHint.Range, "0,20,0.1,or_greater")]
public float WalkSpeed { get; set; } = 5.0f;
@ -31,9 +31,6 @@ public partial class PlayerController : CharacterBody3D
[Export(PropertyHint.Range, "0,5,0.1,or_greater")]
public float DoubleJumpSpeedFactor { get; set; } = 2f;
[Export(PropertyHint.Range, "1,50,1,or_greater")]
public float ControllerSensitivity { get; set; } = 20f;
private bool _canDoubleJump = true;
private bool _movementEnabled = true;
@ -100,7 +97,8 @@ public partial class PlayerController : CharacterBody3D
{
_currentSpeed = WalkSpeed;
Head = GetNode<Node3D>("Head");
HeadSystem = GetNode<HeadSystem>("HeadSystem");
HeadSystem.Init();
_headCollisionDetectors = new RayCast3D[NumOfHeadCollisionDetectors];
@ -111,25 +109,23 @@ public partial class PlayerController : CharacterBody3D
}
// Getting dependencies of the components(In godot we manage this from upwards to downwards not vice versa)
Camera3D camera = GetNode<Camera3D>("Head/CameraSmooth/Camera3D");
Camera3D camera = GetNode<Camera3D>("HeadSystem/CameraSmooth/Camera3D");
RayCast3D stairsBelowRayCast3D = GetNode<RayCast3D>("StairsBelowRayCast3D");
RayCast3D stairsAheadRayCast3D = GetNode<RayCast3D>("StairsAheadRayCast3D");
Node3D cameraSmooth = GetNode<Node3D>("Head/CameraSmooth");
AnimationPlayer animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
Node3D cameraSmooth = GetNode<Node3D>("HeadSystem/CameraSmooth");
// Getting universal setting from GODOT editor to be in sync
float gravitySetting = (float)ProjectSettings.GetSetting("physics/3d/default_gravity");
ColorRect vignetteRect = GetNode<ColorRect>(
"Head/CameraSmooth/Camera3D/CLVignette(Layer_1)/HealthVignetteRect");
"HeadSystem/CameraSmooth/Camera3D/CLVignette(Layer_1)/HealthVignetteRect");
ColorRect distortionRect = GetNode<ColorRect>(
"Head/CameraSmooth/Camera3D/CLDistortion(Layer_2)/HealthDistortionRect");
"HeadSystem/CameraSmooth/Camera3D/CLDistortion(Layer_2)/HealthDistortionRect");
ColorRect blurRect = GetNode<ColorRect>("Head/CameraSmooth/Camera3D/CLBlur(Layer_2)/BlurRect");
ColorRect blurRect = GetNode<ColorRect>("HeadSystem/CameraSmooth/Camera3D/CLBlur(Layer_2)/BlurRect");
Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
@ -148,10 +144,10 @@ public partial class PlayerController : CharacterBody3D
StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth);
MantleSystem = GetNode<MantleSystem>("MantleSystem");
MantleSystem.Init(Head);
MantleSystem.Init(HeadSystem);
DashSystem = GetNode<DashSystem>("DashSystem");
DashSystem.Init(Head, camera);
DashSystem.Init(HeadSystem, camera);
CapsuleCollider = GetNode<CapsuleCollider>("CapsuleCollider");
@ -165,17 +161,13 @@ public partial class PlayerController : CharacterBody3D
Gravity = Gravity,
Parent = this,
Camera = camera,
AnimationPlayer = animationPlayer,
Head = Head,
Head = HeadSystem,
VignetteRect = vignetteRect,
DistortionRect = distortionRect,
BlurRect = blurRect,
};
HealthSystem.Init(healthSystemParams);
Mouse = GetNode<Mouse>("Mouse");
Mouse.Init(Head, camera, HealthSystem.IsDead);
}
private void DisableMovement()
@ -325,16 +317,15 @@ public partial class PlayerController : CharacterBody3D
_currentSpeed = SprintSpeed;
}
// Vector2 inputLookDir = Input.GetVector("look_left", "look_right", "look_up", "look_down");
Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane);
Mouse.LookAround(-1 * ControllerSensitivity * inputLookDir);
HeadSystem.LookAround(inputLookDir);
// Basis is a 3x4 matrix. It contains information about scaling and rotation of head.
// By multiplying our Vector3 by this matrix we're doing multiple things:
// a) We start to operate in global space;
// b) We're applying to Vector3 the current rotation of "head" object;
// c) We're applying to Vector3 the current scaling of "head" object;
Vector3 direction = Head.Transform.Basis * _inputMove;
Vector3 direction = HeadSystem.Transform.Basis * _inputMove;
if (isPlayerDead)
{