can plant weapon in targetables, dash towards it, jump in the air.
This commit is contained in:
@@ -22,27 +22,23 @@ public partial class WeaponSystem : RigidBody3D
|
||||
public StateChartState FlyingState;
|
||||
public StateChartState PlantedState;
|
||||
|
||||
private Node3D _head;
|
||||
private ShapeCast3D _dashCast3D;
|
||||
private Camera3D _camera;
|
||||
private TweenQueueSystem _tweenQueueSystem;
|
||||
|
||||
private Transform3D _startTransform;
|
||||
private Transform3D _startMeshTransform;
|
||||
private Vector3 _startMeshRotation;
|
||||
|
||||
private Vector3 _throwDirection;
|
||||
public Vector3 PlantLocation { get; set; }
|
||||
public Vector3 PlantNormal { get; set; }
|
||||
public Node PlantObject { get; set; }
|
||||
|
||||
public MeshInstance3D WeaponLocationIndicator { get; set; }
|
||||
public StandardMaterial3D WeaponLocationIndicatorMaterial { get; set; }
|
||||
public MeshInstance3D WeaponMesh { get; set; }
|
||||
|
||||
public void Init(Node3D head, Camera3D camera)
|
||||
public void Init()
|
||||
{
|
||||
_head = head;
|
||||
_camera = camera;
|
||||
|
||||
_weaponState = StateChart.Of(GetNode("StateChart"));
|
||||
InHandState = StateChartState.Of(GetNode("StateChart/Root/InHand"));
|
||||
FlyingState = StateChartState.Of(GetNode("StateChart/Root/Flying"));
|
||||
@@ -53,7 +49,7 @@ public partial class WeaponSystem : RigidBody3D
|
||||
WeaponLocationIndicatorMaterial = WeaponLocationIndicator.GetActiveMaterial(0) as StandardMaterial3D;
|
||||
|
||||
WeaponMesh = GetNode<MeshInstance3D>("Weapon");
|
||||
_startMeshTransform = WeaponMesh.Transform;
|
||||
_startMeshRotation = WeaponMesh.Rotation;
|
||||
|
||||
_tweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
|
||||
_tweenQueueSystem.Init(this);
|
||||
@@ -90,7 +86,7 @@ public partial class WeaponSystem : RigidBody3D
|
||||
PlantLocation = location;
|
||||
}
|
||||
|
||||
public void ThrowWeapon(Vector3 end, bool hasHit, Vector3 collisionLocation, Vector3 collisionNormal)
|
||||
public void ThrowWeapon(Vector3 end, bool hasHit, Vector3 collisionLocation, Vector3 collisionNormal, Node collidedObject)
|
||||
{
|
||||
_weaponState.SendEvent("throw");
|
||||
|
||||
@@ -103,11 +99,21 @@ public partial class WeaponSystem : RigidBody3D
|
||||
|
||||
var tween = _tweenQueueSystem.TweenToLocation(new TweenQueueSystem.TweenInputs(end, StraightThrowDuration));
|
||||
if (hasHit)
|
||||
{
|
||||
PlantObject = collidedObject;
|
||||
tween.Finished += PlantWeaponInWall;
|
||||
}
|
||||
else
|
||||
tween.Finished += ThrowWeaponOnCurve;
|
||||
}
|
||||
|
||||
public void RethrowWeapon()
|
||||
{
|
||||
_weaponState.SendEvent("throw");
|
||||
_throwDirection = Vector3.Up;
|
||||
ThrowWeaponOnCurve();
|
||||
}
|
||||
|
||||
public void ThrowWeaponOnCurve()
|
||||
{
|
||||
Freeze = false;
|
||||
@@ -118,16 +124,22 @@ public partial class WeaponSystem : RigidBody3D
|
||||
{
|
||||
_weaponState.SendEvent("plant");
|
||||
|
||||
// WeaponLocationIndicatorMaterial.StencilColor = new Color(1f, 0.2f, 0.2f);
|
||||
|
||||
Freeze = true;
|
||||
GlobalPosition = PlantLocation;
|
||||
WeaponMesh.Transform = _startMeshTransform;
|
||||
LookAt(GlobalTransform.Origin + PlantNormal, Vector3.Up, true);
|
||||
WeaponMesh.Rotation = _startMeshRotation;
|
||||
|
||||
// WeaponLocationIndicatorMaterial.StencilColor = new Color(1f, 0.2f, 0.2f);
|
||||
if (PlantObject is Node3D node)
|
||||
{
|
||||
GetTree().GetRoot().CallDeferred(Node.MethodName.RemoveChild, this);
|
||||
node.CallDeferred(Node.MethodName.AddChild, this);
|
||||
}
|
||||
CallDeferred(Node3D.MethodName.SetGlobalPosition, PlantLocation);
|
||||
CallDeferred(Node3D.MethodName.LookAt, GlobalTransform.Origin + PlantNormal, Vector3.Up, true);
|
||||
}
|
||||
|
||||
public void OnThrownWeaponReachesGround(Node other)
|
||||
{
|
||||
PlantObject = other;
|
||||
PlantWeaponInWall();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ material = SubResource("StandardMaterial3D_m0v1h")
|
||||
|
||||
[node name="Weapon" type="RigidBody3D"]
|
||||
collision_layer = 65536
|
||||
collision_mask = 256
|
||||
collision_mask = 304
|
||||
continuous_cd = true
|
||||
contact_monitor = true
|
||||
max_contacts_reported = 1
|
||||
@@ -54,6 +54,9 @@ shape = SubResource("CylinderShape3D_avini")
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0.8673003)
|
||||
mesh = ExtResource("3_svc06")
|
||||
|
||||
[node name="WeaponLocationIndicator" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_jpdh0")
|
||||
|
||||
[node name="StateChart" type="Node" parent="."]
|
||||
script = ExtResource("3_5owyf")
|
||||
metadata/_custom_type_script = "uid://couw105c3bde4"
|
||||
@@ -89,11 +92,14 @@ delay_in_seconds = "0.0"
|
||||
[node name="Planted" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("5_m0v1h")
|
||||
|
||||
[node name="ToFlying" type="Node" parent="StateChart/Root/Planted"]
|
||||
script = ExtResource("6_jpdh0")
|
||||
to = NodePath("../../Flying")
|
||||
event = &"throw"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="ToHand" type="Node" parent="StateChart/Root/Planted"]
|
||||
script = ExtResource("6_jpdh0")
|
||||
to = NodePath("../../InHand")
|
||||
event = &"recover"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="WeaponLocationIndicator" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_jpdh0")
|
||||
|
||||
Reference in New Issue
Block a user