diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index c3618d9..ae291bf 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -186,8 +186,7 @@ delay_in_seconds = "0.0" [node name="WeaponRoot" type="Node3D" parent="."] [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) -skeleton = NodePath("../..") +transform = Transform3D(1, 0, 0, 0, 0.984902, 0.173115, 0, -0.173115, 0.984902, 0.45268, 1.44035, -0.692528) [connection signal="input_aim_canceled" from="InputController" to="." method="OnInputAimCanceled"] [connection signal="input_aim_pressed" from="InputController" to="." method="OnInputAimPressed"] diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index bbdb978..41dc492 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -119,7 +119,7 @@ public partial class PlayerController : CharacterBody3D MoveSystem.Init(moveSystemParams); StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth); DashSystem.Init(HeadSystem, camera, TweenQueueSystem); - WeaponSystem.Init(HeadSystem, camera, TweenQueueSystem); + WeaponSystem.Init(HeadSystem, camera); // RPG Stuff HealthSystem.HealthSystemInitParams healthSystemParams = new HealthSystem.HealthSystemInitParams() @@ -154,7 +154,9 @@ public partial class PlayerController : CharacterBody3D { var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation; 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) @@ -194,6 +196,8 @@ public partial class PlayerController : CharacterBody3D public void OnDashEnded() { _playerState.SendEvent("dash_ended"); + // AddChild(WeaponSystem); + WeaponSystem.ResetWeapon(); } public void OnInputJumpPressed() diff --git a/systems/tween_queue/TweenQueueSystem.cs b/systems/tween_queue/TweenQueueSystem.cs index dc611b6..9d0deb6 100644 --- a/systems/tween_queue/TweenQueueSystem.cs +++ b/systems/tween_queue/TweenQueueSystem.cs @@ -28,7 +28,7 @@ public partial class TweenQueueSystem : Node3D var (location, duration) = inputs; var tween = GetTree().CreateTween(); - tween.TweenProperty(_tweenObject, "position", location, duration); + tween.TweenProperty(_tweenObject, "global_position", location, duration); tween.TweenCallback(_tweenEndedCallback); _isTweening = true; return tween; diff --git a/systems/weapon/WeaponSystem.cs b/systems/weapon/WeaponSystem.cs index 59c9947..13962e1 100644 --- a/systems/weapon/WeaponSystem.cs +++ b/systems/weapon/WeaponSystem.cs @@ -2,20 +2,60 @@ using Godot; namespace Movementtests.systems; -public partial class WeaponSystem : MeshInstance3D +public partial class WeaponSystem : RigidBody3D { private Node3D _head; private ShapeCast3D _dashCast3D; private Camera3D _camera; private TweenQueueSystem _tweenQueueSystem; + + private Transform3D _startTransform; - private MantleSystem _mantleSystem; - private MeshInstance3D _dashTarget; + private Vector3 _throwDirection; + private Vector3 _plantLocation; + private Vector3 _plantNormal; - public void Init(Node3D head, Camera3D camera, TweenQueueSystem tweenQueueSystem) + public void Init(Node3D head, Camera3D camera) { _head = head; _camera = camera; - _tweenQueueSystem = tweenQueueSystem; + + _tweenQueueSystem = GetNode("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; } } \ No newline at end of file diff --git a/systems/weapon/weapon.tscn b/systems/weapon/weapon.tscn index 11b11fc..497e287 100644 --- a/systems/weapon/weapon.tscn +++ b/systems/weapon/weapon.tscn @@ -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="PackedScene" uid="uid://dbe5f0p6lvqtr" path="res://systems/tween_queue/tween_queue_system.tscn" id="2_x1nha"] -[sub_resource type="CylinderMesh" id="CylinderMesh_q5h8a"] -top_radius = 0.01 -bottom_radius = 0.01 +[sub_resource type="CylinderShape3D" id="CylinderShape3D_avini"] +height = 1.0 +radius = 0.1 + +[sub_resource type="CylinderMesh" id="CylinderMesh_x1nha"] +top_radius = 0.0 +bottom_radius = 0.05 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) -mesh = SubResource("CylinderMesh_q5h8a") 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")