improved weapon system and cleaner weapon setup
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 20s
Create tag and build when new code gets to main / Export (push) Successful in 10m20s

This commit is contained in:
2026-01-19 17:25:12 +01:00
parent 4dd48bed70
commit 4224333963
4 changed files with 36 additions and 32 deletions

View File

@@ -272,9 +272,7 @@ collision_mask = 256
DashSpeed = 0.2
PostDashSpeed = 30.0
[node name="WeaponRoot" type="Node3D" parent="."]
[node name="WeaponSystem" parent="WeaponRoot" instance=ExtResource("29_wv70j")]
[node name="WeaponSystem" parent="." instance=ExtResource("29_wv70j")]
transform = Transform3D(1, 0, 0, 0, 0.173648, -0.984808, 0, 0.984808, 0.173648, 0.45268, 1.44035, -0.692528)
mass = 10.0
gravity_scale = 3.0

View File

@@ -46,7 +46,6 @@ public partial class PlayerController : CharacterBody3D,
public DashSystem DashSystem;
public CollisionShape3D StandingCollider;
public CollisionShape3D SlideCollider;
public Node3D WeaponRoot;
public WeaponSystem WeaponSystem;
public WallHugSystem WallHugSystem;
public PlayerUi PlayerUi;
@@ -309,6 +308,8 @@ public partial class PlayerController : CharacterBody3D,
private StateChartState _onWallHanging;
private StateChartState _onWallRunning;
private Transition _onDashEnded;
private Transition _onJumpFromWall;
private Transition _onJumpFromWallFalling;
private Transition _onLeaveWallFromRun;
@@ -342,8 +343,7 @@ public partial class PlayerController : CharacterBody3D,
Node3D cameraSmooth = GetNode<Node3D>("HeadSystem/CameraSmooth");
// Movement stuff
WeaponRoot = GetNode<Node3D>("WeaponRoot");
WeaponSystem = GetNode<WeaponSystem>("WeaponRoot/WeaponSystem");
WeaponSystem = GetNode<WeaponSystem>("WeaponSystem");
MantleSystem = GetNode<MantleSystem>("HeadSystem/MantleSystem");
StandingCollider = GetNode<CollisionShape3D>("StandingCollider");
SlideCollider = GetNode<CollisionShape3D>("SlideCollider");
@@ -384,6 +384,7 @@ public partial class PlayerController : CharacterBody3D,
_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"));
_onDashEnded = Transition.Of(GetNode("StateChart/Root/Movement/Dashing/OnDashEnded"));
// _actionHanging = StateChartState.Of(GetNode("StateChart/Root/Actions/Hanging"));
_powerExpired = StateChartState.Of(GetNode("StateChart/Root/PowerReserve/Expired"));
@@ -495,6 +496,9 @@ public partial class PlayerController : CharacterBody3D,
_onWallHanging.StatePhysicsProcessing += HandleWallHanging;
_onWallRunning.StatePhysicsProcessing += HandleWallRunning;
_onWallHanging.StateExited += RecoverWeapon;
_onDashEnded.Taken += RecoverWeapon;
_onJumpFromWall.Taken += OnJumpFromWall;
_onJumpFromWallFalling.Taken += OnJumpFromWall;
_onLeaveWallFromRun.Taken += OnLeaveWallFromRun;
@@ -542,9 +546,9 @@ public partial class PlayerController : CharacterBody3D,
if (TutorialDone)
return;
RemoveChild(WeaponRoot);
GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, WeaponRoot);
WeaponRoot.CallDeferred(Node3D.MethodName.SetGlobalPosition, TutorialWeaponTarget.GlobalPosition);
RemoveChild(WeaponSystem);
GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, WeaponSystem);
WeaponSystem.CallDeferred(Node3D.MethodName.SetGlobalPosition, TutorialWeaponTarget.GlobalPosition);
WeaponSystem.CallDeferred(WeaponSystem.MethodName.PlaceWeaponForTutorial, TutorialWeaponTarget.GlobalPosition);
}
@@ -820,10 +824,6 @@ public partial class PlayerController : CharacterBody3D,
FovMultiplier: _fovChangeMultiplier);
HeadSystem.LookAround(lookAroundInputs);
}
public void RotateWeaponWithPlayer()
{
WeaponRoot.SetRotation(HeadSystem.Rotation);
}
public Vector3 GetGlobalForwardFacingVector()
{
return Transform.Basis * HeadSystem.Transform.Basis * Vector3.Forward;
@@ -1554,9 +1554,6 @@ public partial class PlayerController : CharacterBody3D,
}
public void HandleAiming(float delta)
{
if (WeaponSystem.InHandState.Active)
RotateWeaponWithPlayer();
DashIndicatorMeshCylinder.Height = DashSystem.PlannedLocation.DistanceTo(GlobalPosition);
DashIndicatorNode.LookAt(DashSystem.PlannedLocation);
@@ -1624,7 +1621,8 @@ public partial class PlayerController : CharacterBody3D,
public void ThrowWeapon()
{
_playerState.SendEvent("cancel_aim");
RemoveChildNode(WeaponRoot);
RemoveChildNode(WeaponSystem);
HeadSystem.HideWeapon();
var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.PlannedLocation;
WeaponSystem.ThrowWeapon(
@@ -1635,7 +1633,10 @@ public partial class PlayerController : CharacterBody3D,
}
public void RecoverWeapon()
{
RecoverChildNode(WeaponRoot);
if (WeaponSystem.GetParent() == this) return;
HeadSystem.ShowWeapon();
RecoverChildNode(WeaponSystem);
WeaponSystem.ResetWeapon();
}
@@ -1688,8 +1689,6 @@ public partial class PlayerController : CharacterBody3D,
var isPlantedUnderPlatform = WeaponSystem.IsPlantedUnderPlatform();
var shouldDashToHanging = isPlantedOnWall || isPlantedUnderPlatform;
RecoverWeapon();
var resultingEvent = shouldDashToHanging ? "dash_to_planted" : "dash_finished";
_playerState.SendEvent(resultingEvent);
}
@@ -1705,8 +1704,6 @@ public partial class PlayerController : CharacterBody3D,
MoveSlideAndHandleStairs((float) delta);
MantleSystem.ProcessMantle(_grounded.Active);
if (WeaponSystem.InHandState.Active)
RotateWeaponWithPlayer();
if (WeaponSystem.InHandState.Active && !_aiming.Active && TutorialDone)
{
DashIndicatorMesh.Visible = false;

View File

@@ -184,6 +184,15 @@ public partial class HeadSystem : Node3D
_camera.Fov = Mathf.Lerp(_camera.Fov, targetFov, (float) delta * FovChangeSpeed);
}
public void HideWeapon()
{
_fpRig.Visible = false;
}
public void ShowWeapon()
{
_fpRig.Visible = true;
}
public float ComputeCameraInclineFactor(Vector3 direction)
{
var forward = GetForwardHorizontalVector().Normalized();

View File

@@ -28,6 +28,7 @@ public partial class WeaponSystem : RigidBody3D
private TweenQueueSystem _tweenQueueSystem;
private Transform3D _startTransform;
private Transform3D _startMeshTransform;
private Vector3 _throwDirection;
public Vector3 PlantLocation { get; set; }
@@ -36,7 +37,6 @@ public partial class WeaponSystem : RigidBody3D
public MeshInstance3D WeaponLocationIndicator { get; set; }
public StandardMaterial3D WeaponLocationIndicatorMaterial { get; set; }
public MeshInstance3D WeaponMesh { get; set; }
public StandardMaterial3D WeaponMaterial { get; set; }
public void Init(Node3D head, Camera3D camera)
{
@@ -53,7 +53,7 @@ public partial class WeaponSystem : RigidBody3D
WeaponLocationIndicatorMaterial = WeaponLocationIndicator.GetActiveMaterial(0) as StandardMaterial3D;
WeaponMesh = GetNode<MeshInstance3D>("Weapon");
WeaponMaterial = WeaponMesh.GetActiveMaterial(0) as StandardMaterial3D;
_startMeshTransform = WeaponMesh.Transform;
_tweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
_tweenQueueSystem.Init(this);
@@ -71,16 +71,14 @@ public partial class WeaponSystem : RigidBody3D
public void WeaponLeft()
{
Visible = true;
WeaponLocationIndicator.Visible = true;
WeaponMaterial!.UseFovOverride = false;
// WeaponLocationIndicator.Visible = true;
EmitSignalWeaponThrown();
}
public void WeaponBack()
{
Visible = false;
WeaponLocationIndicator.Visible = false;
WeaponMaterial!.UseFovOverride = true;
// WeaponLocationIndicator.Visible = false;
EmitSignalWeaponRetrieved();
}
@@ -96,7 +94,7 @@ public partial class WeaponSystem : RigidBody3D
{
_weaponState.SendEvent("throw");
WeaponLocationIndicatorMaterial.StencilColor = new Color(1f, 1f, 1f);
// WeaponLocationIndicatorMaterial.StencilColor = new Color(1f, 1f, 1f);
_throwDirection = (end - GlobalPosition).Normalized();
PlantLocation = collisionLocation;
@@ -120,10 +118,11 @@ public partial class WeaponSystem : RigidBody3D
{
_weaponState.SendEvent("plant");
WeaponLocationIndicatorMaterial.StencilColor = new Color(1f, 0.2f, 0.2f);
// WeaponLocationIndicatorMaterial.StencilColor = new Color(1f, 0.2f, 0.2f);
Freeze = true;
GlobalPosition = PlantLocation;
WeaponMesh.Transform = _startMeshTransform;
LookAt(GlobalTransform.Origin + PlantNormal, Vector3.Up, true);
}
@@ -151,11 +150,12 @@ public partial class WeaponSystem : RigidBody3D
}
}
public override void _PhysicsProcess(double _delta)
public override void _Process(double delta)
{
if (!FlyingState.Active) return;
LookAt(GlobalTransform.Origin + LinearVelocity.Normalized(), Vector3.Up, false);
WeaponMesh.Rotation = new Vector3(WeaponMesh.Rotation.X, WeaponMesh.Rotation.Y + (float) delta * 100, WeaponMesh.Rotation.Z);
//LookAt(GlobalTransform.Origin + LinearVelocity.Normalized(), Vector3.Up, false);
}
public bool IsPlantedUnderPlatform()