more lights in tutorial and better wall run detection I believe
This commit is contained in:
@@ -229,8 +229,10 @@ public partial class PlayerController : CharacterBody3D,
|
||||
|
||||
// Wall run
|
||||
[ExportGroup("Wall run")]
|
||||
[Export(PropertyHint.Range, "1,20,0.1,or_greater")]
|
||||
public float WallRunUpwardVelocity { get; set; } = 10f;
|
||||
[Export(PropertyHint.Range, "0,2,0.01,or_greater")]
|
||||
public float WallRunUpwardVelocityFactor { get; set; } = 0.05f;
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float MinimumWallRunUpwardVelocity { get; set; } = 2f;
|
||||
[Export(PropertyHint.Range, "1,20,0.1,or_greater")]
|
||||
public float WallRunAltitudeLossSpeed { get; set; } = 10f;
|
||||
|
||||
@@ -851,7 +853,7 @@ public partial class PlayerController : CharacterBody3D,
|
||||
// Should we start a wall run
|
||||
if (ShouldStartWallRun())
|
||||
{
|
||||
SetVerticalVelocity(WallRunUpwardVelocity);
|
||||
SetVerticalVelocity(GetWallRunStartVerticalVelocity());
|
||||
_playerState.SendEvent("wall_run");
|
||||
return;
|
||||
}
|
||||
@@ -864,19 +866,6 @@ public partial class PlayerController : CharacterBody3D,
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShouldStartWallRun()
|
||||
{
|
||||
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 isCoplanarEnough = Velocity.AngleTo(wallNormal) > Math.PI/4 && Velocity.AngleTo(wallNormal) < 3*Math.PI/4;
|
||||
var isGoingDownwards = Velocity.AngleTo(Vector3.Down) < Math.PI/4;
|
||||
var shouldStart = haveEnoughSpeed && isCoplanarEnough && !isGoingDownwards && isIndeedWall;
|
||||
return shouldStart;
|
||||
}
|
||||
|
||||
public float ComputeVerticalSpeedGravity(float delta)
|
||||
{
|
||||
return Velocity.Y - CalculateGravityForce() * delta;
|
||||
@@ -1168,7 +1157,8 @@ public partial class PlayerController : CharacterBody3D,
|
||||
WallHug(delta);
|
||||
if (ShouldStartWallRun())
|
||||
{
|
||||
SetVerticalVelocity(WallRunUpwardVelocity);
|
||||
var verticalVelocity = GetWallRunStartVerticalVelocity();
|
||||
SetVerticalVelocity(verticalVelocity);
|
||||
_playerState.SendEvent("wall_run");
|
||||
return;
|
||||
}
|
||||
@@ -1183,8 +1173,8 @@ public partial class PlayerController : CharacterBody3D,
|
||||
}
|
||||
public void HandleWallRunning(float delta)
|
||||
{
|
||||
_canDash = false;
|
||||
_canDashAirborne = false;
|
||||
// _canDash = false;
|
||||
// _canDashAirborne = false;
|
||||
|
||||
// Find horizontal velocity projected on the current wall
|
||||
var hvel = new Vector3(Velocity.X, 0, Velocity.Z);
|
||||
@@ -1196,7 +1186,7 @@ public partial class PlayerController : CharacterBody3D,
|
||||
// Adapt vertical speed
|
||||
var verticalSpeed = Velocity.Y - WallRunAltitudeLossSpeed * delta;
|
||||
Velocity = finalHVel + Vector3.Up*verticalSpeed;
|
||||
Velocity *= 0.999f;
|
||||
// Velocity *= 0.999f;
|
||||
|
||||
_currentWallContactPoint = WallHugSystem.WallHugLocation.UnwrapOr(Vector3.Zero);
|
||||
|
||||
@@ -1204,7 +1194,42 @@ public partial class PlayerController : CharacterBody3D,
|
||||
_playerState.SendEvent("grounded");
|
||||
if (!WallHugSystem.IsWallHugging())
|
||||
_playerState.SendEvent("start_falling");
|
||||
if (Velocity.Length() < WallRunSpeedThreshold / 2f)
|
||||
_playerState.SendEvent("wall_hug");
|
||||
}
|
||||
|
||||
public float GetWallRunStartVerticalVelocity()
|
||||
{
|
||||
var hvel = new Vector3(Velocity.X, 0, Velocity.Z);
|
||||
var hvelProjected = hvel.Slide(_wallHugStartNormal);
|
||||
return Mathf.Max(hvelProjected.Length() * WallRunUpwardVelocityFactor, MinimumWallRunUpwardVelocity);
|
||||
}
|
||||
|
||||
public bool ShouldStartWallRun()
|
||||
{
|
||||
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 = Velocity.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;
|
||||
var isLookingInDirectionOfRun = hvelProjected.AngleTo(-HeadSystem.GetForwardHorizontalVector()) < Math.PI/2;
|
||||
var shouldStart = haveEnoughSpeed && isCoplanarEnough && !isGoingDownwards && isIndeedWall && isLookingInDirectionOfRun;
|
||||
|
||||
var debugText = "--------------\n";
|
||||
debugText += shouldStart ? "WALL RUN STARTED\n" : "NO WALL RUN\n";
|
||||
debugText += $"Enough speed? {haveEnoughSpeed}\n";
|
||||
debugText += $"Coplanar enough? {isCoplanarEnough}\n";
|
||||
debugText += $"Going downwards? {isGoingDownwards} with angle {Velocity.AngleTo(Vector3.Down)}\n";
|
||||
debugText += $"Is looking in direction of run? {isLookingInDirectionOfRun} with angle {hvelProjected.AngleTo(-HeadSystem.GetForwardHorizontalVector())}\n";
|
||||
debugText += $"HVelocity on wall: {hvelProjected} - Forward H Vector: {-HeadSystem.GetForwardHorizontalVector()}\n";
|
||||
debugText += "--------------\n";
|
||||
//GD.Print(debugText);
|
||||
|
||||
return shouldStart;
|
||||
}
|
||||
|
||||
public void WallHug(float delta)
|
||||
{
|
||||
var hvel = ComputeHVelocity(delta, WallHugHorizontalDeceleration, WallHugHorizontalDeceleration);
|
||||
@@ -1794,7 +1819,7 @@ public partial class PlayerController : CharacterBody3D,
|
||||
var plannedDashLocation = targetable.GetTargetGlobalPosition() + Vector3.Down*_playerHeight/2;
|
||||
travel = plannedDashLocation - GlobalPosition;
|
||||
_dashDirection = travel.Normalized();
|
||||
var postDashLocation = plannedDashLocation + _dashDirection;
|
||||
var postDashLocation = plannedDashLocation + 2*_dashDirection;
|
||||
var wallBehindQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition + Vector3.Up*HeadSystem.Position.Y, postDashLocation, GroundDetector.CollisionMask);
|
||||
var wallBehindResult = _spaceState.IntersectRay(wallBehindQuery);
|
||||
shouldRebound = wallBehindResult.Count > 0;
|
||||
@@ -2131,7 +2156,7 @@ public partial class PlayerController : CharacterBody3D,
|
||||
var travel = plannedDashLocation - GlobalPosition;
|
||||
_dashDirection = travel.Normalized();
|
||||
|
||||
var postDashLocation = plannedDashLocation + _dashDirection;
|
||||
var postDashLocation = plannedDashLocation + 2*_dashDirection;
|
||||
var wallBehindQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition + Vector3.Up*HeadSystem.Position.Y, postDashLocation, GroundDetector.CollisionMask);
|
||||
var wallBehindResult = _spaceState.IntersectRay(wallBehindQuery);
|
||||
var shouldRebound = wallBehindResult.Count > 0;
|
||||
|
||||
Reference in New Issue
Block a user