jumping from slides and some improvement on air gliding
This commit is contained in:
@@ -142,14 +142,27 @@ public partial class PlayerController : CharacterBody3D
|
||||
public float AccelerationGroundSlide = 1.0f;
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float DecelerationGroundSlide = 0.1f;
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float GroundSlideJumpMultiplier = 1.0f;
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float GroundSlideJumpSpeedFactor;
|
||||
|
||||
[ExportSubgroup("Air glide")]
|
||||
[ExportSubgroup("Air glide")]
|
||||
[Export]
|
||||
public bool AllowForVelocityRedirection = true;
|
||||
|
||||
[Export(PropertyHint.Range, "0,10,0.01,or_greater")]
|
||||
public float AirGlideVSpeed { get; set; } = 1.0f;
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float AccelerationAirGlide = 1.0f;
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float DecelerationAirGlide = 0.1f;
|
||||
[Export(PropertyHint.Range, "0,10,0.01,or_greater")]
|
||||
public float AirGlideVerticalAcceleration = 1.0f;
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float AirGlideJumpMultiplier = 1.0f;
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float AirGlideJumpSpeedFactor;
|
||||
|
||||
// Wall hug
|
||||
[ExportGroup("Wall hug")]
|
||||
@@ -260,6 +273,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
private StateChartState _sliding;
|
||||
private StateChartState _groundSliding;
|
||||
private StateChartState _airGliding;
|
||||
private StateChartState _airGlidingDoubleJump;
|
||||
private StateChartState _slamming;
|
||||
private StateChartState _onWall;
|
||||
private StateChartState _onWallHugging;
|
||||
@@ -269,6 +283,9 @@ public partial class PlayerController : CharacterBody3D
|
||||
private Transition _onJumpFromWall;
|
||||
private Transition _onJumpFromWallFalling;
|
||||
private Transition _onLeaveWallFromRun;
|
||||
|
||||
private Transition _onGroundSlideJump;
|
||||
private Transition _onAirGlideDoubleJump;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -326,11 +343,14 @@ public partial class PlayerController : CharacterBody3D
|
||||
_aiming = StateChartState.Of(GetNode("StateChart/Root/Aim/On"));
|
||||
_simpleDash = StateChartState.Of(GetNode("StateChart/Root/Movement/Dashing/Dash"));
|
||||
_aimedDash = StateChartState.Of(GetNode("StateChart/Root/Movement/Dashing/AimedDash"));
|
||||
_slamming = StateChartState.Of(GetNode("StateChart/Root/Movement/Slamming"));
|
||||
|
||||
_sliding = StateChartState.Of(GetNode("StateChart/Root/Movement/Sliding"));
|
||||
_groundSliding = StateChartState.Of(GetNode("StateChart/Root/Movement/Sliding/GroundSlide"));
|
||||
_airGliding = StateChartState.Of(GetNode("StateChart/Root/Movement/Sliding/AirGlide"));
|
||||
_slamming = StateChartState.Of(GetNode("StateChart/Root/Movement/Slamming"));
|
||||
_airGlidingDoubleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Sliding/AirGlideDoubleJumpEnabled"));
|
||||
_onGroundSlideJump = Transition.Of(GetNode("StateChart/Root/Movement/Sliding/GroundSlide/OnJump"));
|
||||
_onAirGlideDoubleJump = Transition.Of(GetNode("StateChart/Root/Movement/Sliding/AirGlideDoubleJumpEnabled/OnJump"));
|
||||
|
||||
// _actionHanging = StateChartState.Of(GetNode("StateChart/Root/Actions/Hanging"));
|
||||
_powerExpired = StateChartState.Of(GetNode("StateChart/Root/PowerReserve/Expired"));
|
||||
@@ -423,6 +443,10 @@ public partial class PlayerController : CharacterBody3D
|
||||
_sliding.StateExited += SlideEnded;
|
||||
_groundSliding.StatePhysicsProcessing += HandleGroundSlide;
|
||||
_airGliding.StatePhysicsProcessing += HandleAirGlide;
|
||||
_airGlidingDoubleJump.StatePhysicsProcessing += HandleAirGlide;
|
||||
|
||||
_onGroundSlideJump.Taken += JumpFromGroundSlide;
|
||||
_onAirGlideDoubleJump.Taken += JumpFromAirGlide;
|
||||
|
||||
_slamming.StateEntered += SlamStarted;
|
||||
_slamming.StateExited += SlamEnded;
|
||||
@@ -1063,11 +1087,13 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
_playerState.SendEvent("jump");
|
||||
}
|
||||
|
||||
|
||||
private float _jumpStrengthMultiplier = 1.0f;
|
||||
public void OnJumpStarted(float verticalVelocity)
|
||||
{
|
||||
_framesSinceJumpAtApex = 0;
|
||||
SetVerticalVelocity(verticalVelocity);
|
||||
SetVerticalVelocity(verticalVelocity*_jumpStrengthMultiplier);
|
||||
_jumpStrengthMultiplier = 1.0f;
|
||||
}
|
||||
public void OnSimpleJumpStarted()
|
||||
{
|
||||
@@ -1201,7 +1227,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
var positionDifference = GlobalPosition - _mantleStartPosition;
|
||||
var directionHorizontal = new Vector3(positionDifference.X, 0, positionDifference.Z);
|
||||
// SimpleDashInDirection(directionHorizontal.Normalized());
|
||||
SetVelocity(directionHorizontal.Normalized() * WalkSpeed);
|
||||
SetVelocity(directionHorizontal.Normalized() * _velocityOnMantleStarted.Length());
|
||||
}
|
||||
|
||||
_customMantle = false;
|
||||
@@ -1226,27 +1252,47 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void SlideOnGround(float delta)
|
||||
{
|
||||
var currentVelocity = Velocity.Length();
|
||||
var horizontalVelocity = ComputeHVelocity(delta, AccelerationGroundSlide, DecelerationGroundSlide);
|
||||
Velocity = new Vector3(horizontalVelocity.X, Velocity.Y, horizontalVelocity.Z);
|
||||
var newVelocity = new Vector3(horizontalVelocity.X, Velocity.Y, horizontalVelocity.Z);
|
||||
Velocity = newVelocity.Normalized() * currentVelocity; // prevent from losing momentum
|
||||
}
|
||||
public void HandleGroundSlide(float delta)
|
||||
{
|
||||
// GD.Print(GetFloorAngle());
|
||||
|
||||
SlideOnGround(delta);
|
||||
if (MantleSystem.IsMantlePossible && IsPlayerInputtingForward()) _playerState.SendEvent("mantle");
|
||||
|
||||
if (!isOnFloorCustom())
|
||||
_playerState.SendEvent("start_falling");
|
||||
}
|
||||
|
||||
public void GlideInAir(float delta)
|
||||
{
|
||||
var horizontalVelocity = ComputeHVelocity(delta, AccelerationAirGlide, DecelerationAirGlide);
|
||||
|
||||
float verticalSpeed;
|
||||
if (Velocity.Y < -AirGlideVSpeed) verticalSpeed = -AirGlideVSpeed;
|
||||
else if (Velocity.Y > 0) verticalSpeed = ComputeVerticalSpeedGravity(delta);
|
||||
else verticalSpeed = Mathf.Lerp(Velocity.Y, -AirGlideVSpeed, delta);
|
||||
|
||||
Velocity = new Vector3(horizontalVelocity.X, verticalSpeed, horizontalVelocity.Z);
|
||||
if (AllowForVelocityRedirection)
|
||||
{
|
||||
// Preserve overall velocity
|
||||
// Allows for tragic reorientation of the velocity vector after a fall
|
||||
// Allows for bunny-hoping-like movement
|
||||
var currentVelocity = Velocity.Length();
|
||||
var horizontalVelocity = ComputeHVelocity(delta, AccelerationAirGlide, DecelerationAirGlide);
|
||||
var verticalSpeed = Velocity.Y > 0 ? ComputeVerticalSpeedGravity(delta) : Mathf.Lerp(Velocity.Y, -AirGlideVSpeed, delta*AirGlideVerticalAcceleration);
|
||||
var newVelocity = new Vector3(horizontalVelocity.X, verticalSpeed, horizontalVelocity.Z);
|
||||
Velocity = newVelocity.Normalized() * currentVelocity;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Preserve horizontal velocity only
|
||||
// Allows for mor stable descent when gliding because you don't zoom away after a long fall
|
||||
// Removes bunny-hoping-like movement by simply holding slide and jump jump jump
|
||||
var currentHVelocity = new Vector2(Velocity.X, Velocity.Z).Length();
|
||||
var horizontalVelocity = ComputeHVelocity(delta, AccelerationAirGlide, DecelerationAirGlide);
|
||||
var newHVelocity = horizontalVelocity.Normalized() * currentHVelocity;
|
||||
var verticalSpeed = Velocity.Y > 0 ? ComputeVerticalSpeedGravity(delta) : Mathf.Lerp(Velocity.Y, -AirGlideVSpeed, delta*AirGlideVerticalAcceleration);
|
||||
var newVelocity = new Vector3(newHVelocity.X, verticalSpeed, newHVelocity.Z);
|
||||
Velocity = newVelocity;
|
||||
}
|
||||
}
|
||||
public void HandleAirGlide(float delta)
|
||||
{
|
||||
@@ -1260,6 +1306,16 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
_targetSpeed = WalkSpeed;
|
||||
}
|
||||
|
||||
public void JumpFromGroundSlide()
|
||||
{
|
||||
_jumpStrengthMultiplier = GroundSlideJumpMultiplier + Velocity.Length()*GroundSlideJumpSpeedFactor;
|
||||
}
|
||||
|
||||
public void JumpFromAirGlide()
|
||||
{
|
||||
_jumpStrengthMultiplier = AirGlideJumpMultiplier + Velocity.Length()*AirGlideJumpSpeedFactor;
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Slam Management ///////
|
||||
|
||||
Reference in New Issue
Block a user