gd: broken weapon throw

This commit is contained in:
2025-06-06 23:21:56 +02:00
parent 579b523a37
commit c2a8b939e8
5 changed files with 72 additions and 16 deletions

View File

@ -186,8 +186,7 @@ delay_in_seconds = "0.0"
[node name="WeaponRoot" type="Node3D" parent="."] [node name="WeaponRoot" type="Node3D" parent="."]
[node name="WeaponSystem" parent="WeaponRoot" instance=ExtResource("29_wv70j")] [node name="WeaponSystem" parent="WeaponRoot" instance=ExtResource("29_wv70j")]
transform = Transform3D(1, 0, 0, 0, 0.953043, 0.302836, 0, -0.302836, 0.953043, 0.45268, 1.44035, -0.692528) transform = Transform3D(1, 0, 0, 0, 0.984902, 0.173115, 0, -0.173115, 0.984902, 0.45268, 1.44035, -0.692528)
skeleton = NodePath("../..")
[connection signal="input_aim_canceled" from="InputController" to="." method="OnInputAimCanceled"] [connection signal="input_aim_canceled" from="InputController" to="." method="OnInputAimCanceled"]
[connection signal="input_aim_pressed" from="InputController" to="." method="OnInputAimPressed"] [connection signal="input_aim_pressed" from="InputController" to="." method="OnInputAimPressed"]

View File

@ -119,7 +119,7 @@ public partial class PlayerController : CharacterBody3D
MoveSystem.Init(moveSystemParams); MoveSystem.Init(moveSystemParams);
StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth); StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth);
DashSystem.Init(HeadSystem, camera, TweenQueueSystem); DashSystem.Init(HeadSystem, camera, TweenQueueSystem);
WeaponSystem.Init(HeadSystem, camera, TweenQueueSystem); WeaponSystem.Init(HeadSystem, camera);
// RPG Stuff // RPG Stuff
HealthSystem.HealthSystemInitParams healthSystemParams = new HealthSystem.HealthSystemInitParams() HealthSystem.HealthSystemInitParams healthSystemParams = new HealthSystem.HealthSystemInitParams()
@ -154,7 +154,9 @@ public partial class PlayerController : CharacterBody3D
{ {
var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation; var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation;
var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve; var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve;
var weaponThrowVector = dashLocation - Position; WeaponSystem.ThrowWeapon(Position, dashLocation, hasHit, collisionPoint, collisionNormal);
DashSystem.CancelDash();
// RemoveChild(WeaponSystem);
} }
public void OnInputMove(Vector3 value) public void OnInputMove(Vector3 value)
@ -194,6 +196,8 @@ public partial class PlayerController : CharacterBody3D
public void OnDashEnded() public void OnDashEnded()
{ {
_playerState.SendEvent("dash_ended"); _playerState.SendEvent("dash_ended");
// AddChild(WeaponSystem);
WeaponSystem.ResetWeapon();
} }
public void OnInputJumpPressed() public void OnInputJumpPressed()

View File

@ -28,7 +28,7 @@ public partial class TweenQueueSystem : Node3D
var (location, duration) = inputs; var (location, duration) = inputs;
var tween = GetTree().CreateTween(); var tween = GetTree().CreateTween();
tween.TweenProperty(_tweenObject, "position", location, duration); tween.TweenProperty(_tweenObject, "global_position", location, duration);
tween.TweenCallback(_tweenEndedCallback); tween.TweenCallback(_tweenEndedCallback);
_isTweening = true; _isTweening = true;
return tween; return tween;

View File

@ -2,20 +2,60 @@ using Godot;
namespace Movementtests.systems; namespace Movementtests.systems;
public partial class WeaponSystem : MeshInstance3D public partial class WeaponSystem : RigidBody3D
{ {
private Node3D _head; private Node3D _head;
private ShapeCast3D _dashCast3D; private ShapeCast3D _dashCast3D;
private Camera3D _camera; private Camera3D _camera;
private TweenQueueSystem _tweenQueueSystem; private TweenQueueSystem _tweenQueueSystem;
private Transform3D _startTransform;
private MantleSystem _mantleSystem; private Vector3 _throwDirection;
private MeshInstance3D _dashTarget; private Vector3 _plantLocation;
private Vector3 _plantNormal;
public void Init(Node3D head, Camera3D camera, TweenQueueSystem tweenQueueSystem) public void Init(Node3D head, Camera3D camera)
{ {
_head = head; _head = head;
_camera = camera; _camera = camera;
_tweenQueueSystem = tweenQueueSystem;
_tweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
_tweenQueueSystem.Init(this);
_startTransform = Transform;
Freeze = true;
}
public void ThrowWeapon(Vector3 start, Vector3 end, bool hasHit, Vector3 collisionLocation, Vector3 collisionNormal)
{
_throwDirection = (end - start).Normalized();
_plantLocation = collisionLocation;
_plantNormal = collisionNormal;
LookAt(GlobalTransform.Origin + _throwDirection);
RotateX(-Mathf.Pi / 2);
var tween = _tweenQueueSystem.TweenToLocation(new TweenQueueSystem.TweenInputs(end, 1f));
if (hasHit)
tween.Finished += PlantWeaponInWall;
else
tween.Finished += ThrowWeaponOnCurve;
}
public void ThrowWeaponOnCurve()
{
Freeze = false;
}
public void PlantWeaponInWall()
{
Position = _plantLocation;
LookAt(_plantLocation + _plantNormal, Vector3.Up);
}
public void ResetWeapon()
{
Transform = _startTransform;
Freeze = true;
} }
} }

View File

@ -1,13 +1,26 @@
[gd_scene load_steps=3 format=3 uid="uid://ckm3d6k08a72u"] [gd_scene load_steps=5 format=3 uid="uid://ckm3d6k08a72u"]
[ext_resource type="Script" uid="uid://iii3wfto4t5b" path="res://systems/weapon/WeaponSystem.cs" id="1_csqwk"] [ext_resource type="Script" uid="uid://iii3wfto4t5b" path="res://systems/weapon/WeaponSystem.cs" id="1_csqwk"]
[ext_resource type="PackedScene" uid="uid://dbe5f0p6lvqtr" path="res://systems/tween_queue/tween_queue_system.tscn" id="2_x1nha"]
[sub_resource type="CylinderMesh" id="CylinderMesh_q5h8a"] [sub_resource type="CylinderShape3D" id="CylinderShape3D_avini"]
top_radius = 0.01 height = 1.0
bottom_radius = 0.01 radius = 0.1
[sub_resource type="CylinderMesh" id="CylinderMesh_x1nha"]
top_radius = 0.0
bottom_radius = 0.05
height = 1.0 height = 1.0
[node name="Weapon" type="MeshInstance3D"] [node name="Weapon" type="RigidBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
mesh = SubResource("CylinderMesh_q5h8a")
script = ExtResource("1_csqwk") script = ExtResource("1_csqwk")
[node name="TweenQueueSystem" parent="." instance=ExtResource("2_x1nha")]
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
shape = SubResource("CylinderShape3D_avini")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("CylinderMesh_x1nha")