gd: some weapon planting and dashing
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Godot;
|
||||
using GodotStateCharts;
|
||||
|
||||
namespace Movementtests.systems;
|
||||
|
||||
@ -9,6 +10,11 @@ public partial class WeaponSystem : RigidBody3D
|
||||
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
|
||||
public float StraightThrowDuration { get; set; } = 0.1f;
|
||||
|
||||
private StateChart _weaponState;
|
||||
public StateChartState InHandState;
|
||||
public StateChartState FlyingState;
|
||||
public StateChartState PlantedState;
|
||||
|
||||
private Node3D _head;
|
||||
private ShapeCast3D _dashCast3D;
|
||||
private Camera3D _camera;
|
||||
@ -19,21 +25,31 @@ public partial class WeaponSystem : RigidBody3D
|
||||
private Vector3 _throwDirection;
|
||||
private Vector3 _plantLocation;
|
||||
private Vector3 _plantNormal;
|
||||
public Vector3 PlayerDashLocation { get; set; }
|
||||
|
||||
public void Init(Node3D head, Camera3D camera)
|
||||
{
|
||||
_head = head;
|
||||
_camera = camera;
|
||||
|
||||
_weaponState = StateChart.Of(GetNode("StateChart"));
|
||||
InHandState = StateChartState.Of(GetNode("StateChart/Root/InHand"));
|
||||
FlyingState = StateChartState.Of(GetNode("StateChart/Root/Flying"));
|
||||
PlantedState = StateChartState.Of(GetNode("StateChart/Root/Planted"));
|
||||
|
||||
_tweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
|
||||
_tweenQueueSystem.Init(this);
|
||||
|
||||
_startTransform = Transform;
|
||||
Freeze = true;
|
||||
|
||||
BodyEntered += OnThrownWeaponReachesGround;
|
||||
}
|
||||
|
||||
public void ThrowWeapon(Vector3 end, bool hasHit, Vector3 collisionLocation, Vector3 collisionNormal)
|
||||
{
|
||||
_weaponState.SendEvent("throw");
|
||||
|
||||
_throwDirection = (end - GlobalPosition).Normalized();
|
||||
_plantLocation = collisionLocation;
|
||||
_plantNormal = collisionNormal;
|
||||
@ -54,6 +70,7 @@ public partial class WeaponSystem : RigidBody3D
|
||||
|
||||
public void PlantWeaponInWall()
|
||||
{
|
||||
_weaponState.SendEvent("plant");
|
||||
Freeze = true;
|
||||
GlobalPosition = _plantLocation;
|
||||
LookAt(GlobalTransform.Origin + _plantNormal, Vector3.Up, true);
|
||||
@ -61,6 +78,7 @@ public partial class WeaponSystem : RigidBody3D
|
||||
|
||||
public void ResetWeapon()
|
||||
{
|
||||
_weaponState.SendEvent("recover");
|
||||
Transform = _startTransform;
|
||||
Freeze = true;
|
||||
}
|
||||
@ -68,10 +86,12 @@ public partial class WeaponSystem : RigidBody3D
|
||||
public override void _IntegrateForces(PhysicsDirectBodyState3D state)
|
||||
{
|
||||
base._IntegrateForces(state);
|
||||
PlayerDashLocation = GlobalPosition;
|
||||
if (!Freeze && state.GetContactCount() > 0)
|
||||
{
|
||||
_plantLocation = state.GetContactLocalPosition(0);
|
||||
_plantNormal = state.GetContactLocalNormal(0);
|
||||
PlayerDashLocation = _plantLocation + _plantNormal * 0.1f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://ckm3d6k08a72u"]
|
||||
[gd_scene load_steps=9 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"]
|
||||
[ext_resource type="Script" uid="uid://couw105c3bde4" path="res://addons/godot_state_charts/state_chart.gd" id="3_5owyf"]
|
||||
[ext_resource type="Script" uid="uid://jk2jm1g6q853" path="res://addons/godot_state_charts/compound_state.gd" id="4_svc06"]
|
||||
[ext_resource type="Script" uid="uid://cytafq8i1y8qm" path="res://addons/godot_state_charts/atomic_state.gd" id="5_m0v1h"]
|
||||
[ext_resource type="Script" uid="uid://cf1nsco3w0mf6" path="res://addons/godot_state_charts/transition.gd" id="6_jpdh0"]
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_avini"]
|
||||
height = 1.0
|
||||
@ -29,4 +33,43 @@ shape = SubResource("CylinderShape3D_avini")
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0)
|
||||
mesh = SubResource("CylinderMesh_x1nha")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="OnThrownWeaponReachesGround"]
|
||||
[node name="StateChart" type="Node" parent="."]
|
||||
script = ExtResource("3_5owyf")
|
||||
metadata/_custom_type_script = "uid://couw105c3bde4"
|
||||
|
||||
[node name="Root" type="Node" parent="StateChart"]
|
||||
script = ExtResource("4_svc06")
|
||||
initial_state = NodePath("InHand")
|
||||
|
||||
[node name="InHand" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("5_m0v1h")
|
||||
|
||||
[node name="ToFlying" type="Node" parent="StateChart/Root/InHand"]
|
||||
script = ExtResource("6_jpdh0")
|
||||
to = NodePath("../../Flying")
|
||||
event = &"throw"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="Flying" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("5_m0v1h")
|
||||
|
||||
[node name="ToHand" type="Node" parent="StateChart/Root/Flying"]
|
||||
script = ExtResource("6_jpdh0")
|
||||
to = NodePath("../../InHand")
|
||||
event = &"recover"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="ToPlanted" type="Node" parent="StateChart/Root/Flying"]
|
||||
script = ExtResource("6_jpdh0")
|
||||
to = NodePath("../../Planted")
|
||||
event = &"plant"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="Planted" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("5_m0v1h")
|
||||
|
||||
[node name="ToHand" type="Node" parent="StateChart/Root/Planted"]
|
||||
script = ExtResource("6_jpdh0")
|
||||
to = NodePath("../../InHand")
|
||||
event = &"recover"
|
||||
delay_in_seconds = "0.0"
|
||||
|
Reference in New Issue
Block a user