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

@ -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;

View File

@ -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");
_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="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")