Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ff8cc74cc | |||
| fabafbb35b |
@@ -30,6 +30,7 @@ glow_enabled = true
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_1s2y7")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1.5)
|
||||
TutorialDone = true
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_1bvp3")
|
||||
|
||||
@@ -84,6 +84,14 @@ PostDashSpeed = 30.0
|
||||
WallHugGravityLesseningFactor = 15.0
|
||||
WallHugDownwardMaxSpeed = 8.0
|
||||
WallHugHorizontalDeceleration = 0.5
|
||||
WallRunAltitudeLossSpeed = 12.0
|
||||
WallRunSpeedThreshold = 5.0
|
||||
|
||||
[node name="WallRunSnapper" type="RayCast3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(0.99999994, 0, 0, 0, 1, 0, 0, 0, 0.99999994, 0, 0, 0)
|
||||
target_position = Vector3(0, 0, -5)
|
||||
collision_mask = 2
|
||||
|
||||
[node name="InputController" type="Node3D" parent="."]
|
||||
script = ExtResource("16_v31n3")
|
||||
@@ -121,6 +129,8 @@ CapsuleDefaultHeight = 1.7
|
||||
|
||||
[node name="HeadSystem" parent="." instance=ExtResource("11_rxwoh")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.6, 0)
|
||||
CameraInclineAcceleration = 20.0
|
||||
GroundedCameraIncline = 3.0
|
||||
|
||||
[node name="StairsSystem" type="Node3D" parent="."]
|
||||
script = ExtResource("7_bmt5a")
|
||||
@@ -163,7 +173,6 @@ target_position = Vector3(0, 1, 0)
|
||||
[node name="TweenQueueSystem" parent="." instance=ExtResource("22_rpwev")]
|
||||
|
||||
[node name="WallHugSystem" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
script = ExtResource("27_n7qhm")
|
||||
|
||||
[node name="back" type="RayCast3D" parent="WallHugSystem"]
|
||||
|
||||
@@ -35,6 +35,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
public Node3D DashIndicatorNode;
|
||||
public MeshInstance3D DashIndicatorMesh;
|
||||
public CylinderMesh DashIndicatorMeshCylinder;
|
||||
public RayCast3D WallRunSnapper;
|
||||
|
||||
private bool _movementEnabled = true;
|
||||
|
||||
@@ -154,6 +155,16 @@ public partial class PlayerController : CharacterBody3D
|
||||
[Export(PropertyHint.Range, "0.1,10,0.1,or_greater")]
|
||||
public float WallHugHorizontalDeceleration { get; set; } = 5f;
|
||||
|
||||
// Wall run
|
||||
[ExportGroup("Wall run")]
|
||||
[Export(PropertyHint.Range, "1,20,0.1,or_greater")]
|
||||
public float WallRunUpwardVelocity { get; set; } = 10f;
|
||||
[Export(PropertyHint.Range, "1,20,0.1,or_greater")]
|
||||
public float WallRunAltitudeLossSpeed { get; set; } = 10f;
|
||||
|
||||
[Export(PropertyHint.Range, "1,20,0.1,or_greater")]
|
||||
public float WallRunSpeedThreshold { get; set; } = 8f;
|
||||
|
||||
private float _targetSpeed;
|
||||
private float _gravity;
|
||||
|
||||
@@ -246,6 +257,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
DashSystem = GetNode<DashSystem>("DashSystem");
|
||||
StairsSystem = GetNode<StairsSystem>("StairsSystem");
|
||||
WallHugSystem = GetNode<WallHugSystem>("WallHugSystem");
|
||||
WallRunSnapper = GetNode<RayCast3D>("%WallRunSnapper");
|
||||
RayCast3D stairsBelowRayCast3D = GetNode<RayCast3D>("StairsBelowRayCast3D");
|
||||
RayCast3D stairsAheadRayCast3D = GetNode<RayCast3D>("StairsAheadRayCast3D");
|
||||
_headCollisionDetectors = new RayCast3D[NUM_OF_HEAD_COLLISION_DETECTORS];
|
||||
@@ -427,8 +439,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
_playerState.SendEvent("start_falling");
|
||||
}
|
||||
|
||||
private float _wallRunSpeedThreshold = 8f;
|
||||
|
||||
public void HandleAirborne(float delta)
|
||||
{
|
||||
MoveInAir(delta);
|
||||
@@ -444,19 +454,21 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
// Should we start a wall run
|
||||
var wallNormal = WallHugSystem.WallHugNormal.UnwrapOr(Vector3.Zero);
|
||||
var isIndeedWall = wallNormal.Y < 0.1;
|
||||
var hvel = new Vector3(Velocity.X, 0, Velocity.Z);
|
||||
var hvelProjected = hvel.Slide(_wallHugStartNormal);
|
||||
var haveEnoughSpeed = hvelProjected.Length() > _wallRunSpeedThreshold;
|
||||
var isHeadPlanting = Velocity.AngleTo(wallNormal) < Math.PI / 4;
|
||||
var isGoingDownwards = Velocity.AngleTo(Vector3.Down) < Math.PI / 4;
|
||||
if (haveEnoughSpeed && !isHeadPlanting && !isGoingDownwards)
|
||||
var haveEnoughSpeed = hvelProjected.Length() > WallRunSpeedThreshold;
|
||||
var isCoplanarEnough = Velocity.AngleTo(wallNormal) > Math.PI/4 && Velocity.AngleTo(wallNormal) < 3*Math.PI/4;
|
||||
var isGoingDownwards = Velocity.AngleTo(Vector3.Down) < Math.PI/4;
|
||||
if (haveEnoughSpeed && isCoplanarEnough && !isGoingDownwards && isIndeedWall && !_coyoteEnabled.Active)
|
||||
{
|
||||
SetVerticalVelocity(WallRunUpwardVelocity);
|
||||
_playerState.SendEvent("wall_run");
|
||||
return;
|
||||
}
|
||||
|
||||
// If all else fail and we go down, we hug
|
||||
if (Velocity.Y < 0)
|
||||
if (Velocity.Y < 0 && !_coyoteEnabled.Active)
|
||||
_playerState.SendEvent("wall_hug");
|
||||
|
||||
}
|
||||
@@ -464,6 +476,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
private Vector3 _wallHugStartLocation = Vector3.Zero;
|
||||
private Vector3 _wallHugStartNormal = Vector3.Zero;
|
||||
private Vector3 _wallHugStartProjectedVelocity = Vector3.Zero;
|
||||
private Vector3 _currentWallContactPoint = Vector3.Zero;
|
||||
|
||||
public void OnWallDetected()
|
||||
{
|
||||
@@ -476,18 +489,20 @@ public partial class PlayerController : CharacterBody3D
|
||||
_wallHugStartNormal = newWallNormal;
|
||||
}
|
||||
|
||||
private float _timeSinceWallStarted;
|
||||
|
||||
public void OnWallStarted()
|
||||
{
|
||||
_wallHugStartNormal = WallHugSystem.WallHugNormal.UnwrapOr(Vector3.Up);
|
||||
_wallHugStartLocation = WallHugSystem.WallHugLocation.UnwrapOr(Vector3.Zero) + _wallHugStartNormal * _playerRadius;
|
||||
_currentWallContactPoint = WallHugSystem.WallHugLocation.UnwrapOr(Vector3.Zero);
|
||||
_wallHugStartLocation = _currentWallContactPoint + _wallHugStartNormal * _playerRadius;
|
||||
_wallHugStartProjectedVelocity = Velocity.Slide(_wallHugStartNormal);
|
||||
_timeSinceWallStarted = 0;
|
||||
}
|
||||
|
||||
public void OnWallStopped()
|
||||
{
|
||||
_wallHugStartLocation = Vector3.Zero;
|
||||
_currentWallContactPoint = Vector3.Zero;
|
||||
_wallHugStartNormal = Vector3.Zero;
|
||||
_wallHugStartProjectedVelocity = Vector3.Zero;
|
||||
}
|
||||
|
||||
public void HandleWallHugging(float delta)
|
||||
@@ -505,23 +520,25 @@ public partial class PlayerController : CharacterBody3D
|
||||
WallHang(delta);
|
||||
}
|
||||
|
||||
private float _wallRunUpwardVelocity = 10f;
|
||||
|
||||
public void HandleWallRunning(float delta)
|
||||
{
|
||||
_timeSinceWallStarted += delta;
|
||||
|
||||
// Find horizontal velocity projected on the current wall
|
||||
var hvel = new Vector3(Velocity.X, 0, Velocity.Z);
|
||||
var hvelProjected = hvel.Slide(_wallHugStartNormal);
|
||||
Velocity = hvelProjected + hvelProjected.Length()*Vector3.Up*0.3f/(1+_timeSinceWallStarted);
|
||||
Velocity *= 0.99f;
|
||||
|
||||
// if (CanMantle())
|
||||
// {
|
||||
// MantleToLocation(_plannedMantleLocation.Unwrap());
|
||||
// }
|
||||
|
||||
if (!WallHugSystem.IsWallHugging() || Velocity.Length() < _wallRunSpeedThreshold)
|
||||
// Reorient horizontal velocity so we keep it coplanar with the wall without losing speed
|
||||
var finalHVel = hvelProjected.Normalized() * hvel.Length();
|
||||
|
||||
// Adapt vertical speed
|
||||
var verticalSpeed = Velocity.Y - WallRunAltitudeLossSpeed * delta;
|
||||
Velocity = finalHVel + Vector3.Up*verticalSpeed;
|
||||
Velocity *= 0.995f;
|
||||
|
||||
_currentWallContactPoint = WallHugSystem.WallHugLocation.UnwrapOr(Vector3.Zero);
|
||||
|
||||
if (isOnFloorCustom())
|
||||
_playerState.SendEvent("grounded");
|
||||
if (!WallHugSystem.IsWallHugging() || Velocity.Length() < WallRunSpeedThreshold)
|
||||
{
|
||||
_playerState.SendEvent("start_falling");
|
||||
}
|
||||
@@ -549,7 +566,10 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
if (CanMantle())
|
||||
{
|
||||
MantleToLocation(_plannedMantleLocation.Unwrap());
|
||||
var location = _plannedMantleLocation.UnwrapOr(Vector3.Zero);
|
||||
if (location == Vector3.Zero)
|
||||
return; // For some reason CanMantle can return an invalid location so fuck off I guess
|
||||
MantleToLocation(location);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -558,6 +578,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
_playerState.SendEvent("megajump");
|
||||
return;
|
||||
}
|
||||
|
||||
_playerState.SendEvent("jump");
|
||||
}
|
||||
|
||||
@@ -582,6 +603,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
public void OnDoubleJumpStarted()
|
||||
{
|
||||
_canDash = true;
|
||||
_canDashAirborne = true;
|
||||
OnJumpStarted(DoubleJumpStartVelocity);
|
||||
}
|
||||
public void OnMegaJumpStarted()
|
||||
@@ -626,9 +648,14 @@ public partial class PlayerController : CharacterBody3D
|
||||
return _inputMoveKeyboard;
|
||||
}
|
||||
|
||||
public Vector3 GetGlobalMoveInput()
|
||||
{
|
||||
return Transform.Basis * HeadSystem.Transform.Basis * GetMoveInput();
|
||||
}
|
||||
|
||||
public Vector3 ComputeHVelocity(float delta, float accelerationFactor, float decelerationFactor, Vector3? direction = null)
|
||||
{
|
||||
var dir = direction ?? Transform.Basis * HeadSystem.Transform.Basis * GetMoveInput();
|
||||
var dir = direction ?? GetGlobalMoveInput();
|
||||
|
||||
var acceleration = dir.Length() > 0 ? accelerationFactor : decelerationFactor;
|
||||
|
||||
@@ -943,6 +970,9 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
public void PlaceWeaponForTutorial()
|
||||
{
|
||||
if (TutorialDone)
|
||||
return;
|
||||
|
||||
RemoveChild(WeaponRoot);
|
||||
GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, WeaponRoot);
|
||||
WeaponRoot.CallDeferred(Node3D.MethodName.SetGlobalPosition, TutorialWeaponTarget.GlobalPosition);
|
||||
@@ -1076,11 +1106,14 @@ public partial class PlayerController : CharacterBody3D
|
||||
///////////////////////////
|
||||
// Stateless logic ////////
|
||||
///////////////////////////
|
||||
private void LookAround()
|
||||
private void LookAround(double delta)
|
||||
{
|
||||
Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane);
|
||||
var lookSensitivity = _isUsingGamepad ? _lookSensitivityMultiplier : _mouseSensitivityMultiplier;
|
||||
HeadSystem.LookAround(inputLookDir, lookSensitivity);
|
||||
|
||||
var wallHugContactPoint = _onWallRunning.Active ? _currentWallContactPoint : Vector3.Zero;
|
||||
var playerVelocity = GetGlobalMoveInput();
|
||||
HeadSystem.LookAround(delta, inputLookDir, playerVelocity, wallHugContactPoint, lookSensitivity);
|
||||
}
|
||||
|
||||
public void MoveOnGround(double delta)
|
||||
@@ -1158,7 +1191,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
Bobbing.CameraBobbingParams cameraBobbingParams = new Bobbing.CameraBobbingParams
|
||||
{
|
||||
Delta = delta,
|
||||
IsOnFloorCustom = isOnFloorCustom(),
|
||||
IsOnFloorCustom = isOnFloorCustom() || _onWallRunning.Active,
|
||||
Velocity = Velocity,
|
||||
SettingsMultiplier = _headBobbingMultiplier
|
||||
};
|
||||
@@ -1219,7 +1252,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
///////////////////////////
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
LookAround();
|
||||
LookAround(delta);
|
||||
CameraModifications((float) delta);
|
||||
HandleStairs((float) delta);
|
||||
_plannedMantleLocation = MantleSystem.FindMantleForHeadRotation(HeadSystem.Rotation.Y);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Godot;
|
||||
using RustyOptions;
|
||||
|
||||
namespace Movementtests.systems;
|
||||
|
||||
@@ -11,6 +12,15 @@ public partial class HeadSystem : Node3D
|
||||
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float LookSensitivity { get; set; } = 1f;
|
||||
|
||||
[Export(PropertyHint.Range, "0.1,50,0.1,or_greater")]
|
||||
public double CameraInclineAcceleration { get; set; } = 10f;
|
||||
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float WallRunCameraIncline { get; set; } = 5f;
|
||||
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float GroundedCameraIncline { get; set; } = 5f;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
@@ -25,7 +35,7 @@ public partial class HeadSystem : Node3D
|
||||
_animationPlayer.Play("mantle");
|
||||
}
|
||||
|
||||
public void LookAround(Vector2 lookDir, float sensitivitMultiplier = 1f)
|
||||
public void LookAround(double delta, Vector2 lookDir, Vector3 playerVelocity, Vector3? wallContactPoint = null, float sensitivitMultiplier = 1f)
|
||||
{
|
||||
// Horizontal movement of head
|
||||
float angleForHorizontalRotation = lookDir.X * LookSensitivity * sensitivitMultiplier;
|
||||
@@ -35,11 +45,33 @@ public partial class HeadSystem : Node3D
|
||||
Vector3 currentCameraRotation = _cameraAnchor.Rotation;
|
||||
currentCameraRotation.X += Convert.ToSingle(lookDir.Y * LookSensitivity * sensitivitMultiplier);
|
||||
currentCameraRotation.X = Mathf.Clamp(currentCameraRotation.X, Mathf.DegToRad(-90f), Mathf.DegToRad(90f));
|
||||
|
||||
var isWallRunning = wallContactPoint.HasValue && wallContactPoint.Value.Length() > Mathf.Epsilon;
|
||||
var cameraIncline = 0f;
|
||||
if (isWallRunning)
|
||||
{
|
||||
var directionToWall = (wallContactPoint.Value - GlobalPosition).Normalized();
|
||||
var cameraInclineFactor = ComputeCameraInclineFactor(directionToWall);
|
||||
cameraIncline = Mathf.DegToRad(WallRunCameraIncline * cameraInclineFactor);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cameraInclineFactor = ComputeCameraInclineFactor(playerVelocity);
|
||||
cameraIncline = Mathf.DegToRad(GroundedCameraIncline * cameraInclineFactor * -1.0f);
|
||||
}
|
||||
currentCameraRotation.Z = (float) Mathf.Lerp(currentCameraRotation.Z, cameraIncline, delta * CameraInclineAcceleration);
|
||||
_cameraAnchor.Rotation = currentCameraRotation;
|
||||
|
||||
_camera.GlobalTransform = _cameraAnchor.GetGlobalTransformInterpolated();
|
||||
}
|
||||
|
||||
public float ComputeCameraInclineFactor(Vector3 direction)
|
||||
{
|
||||
var forward = GetForwardHorizontalVector().Normalized();
|
||||
var crossProduct = forward.Cross(direction);
|
||||
return crossProduct.Length()*Mathf.Sign(crossProduct.Y);
|
||||
}
|
||||
|
||||
public Vector3 GetForwardHorizontalVector()
|
||||
{
|
||||
return GetGlobalTransform().Basis.Z;
|
||||
|
||||
@@ -33,6 +33,11 @@ public partial class MantleSystem: Node3D
|
||||
{
|
||||
return Option<Vector3>.None;
|
||||
}
|
||||
if (_wallInFrontCast3D.GetCollisionNormal(0).Y > 0.8f)
|
||||
{
|
||||
GD.Print(_wallInFrontCast3D.GetCollisionNormal(0).Y);
|
||||
return Option<Vector3>.None;
|
||||
}
|
||||
|
||||
var collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0);
|
||||
var collisionNormal = _wallInFrontCast3D.GetCollisionNormal(0);
|
||||
|
||||
Reference in New Issue
Block a user