Rotate bullet pattern to face parent

This commit is contained in:
Marco 2025-07-09 12:00:23 +02:00
commit 7d267c406d
19 changed files with 1325 additions and 1245 deletions

View file

@ -17,6 +17,7 @@ public partial class ShootingPattern3D : AttackPattern
[Export] public int bulletCount = 16;
[Export] public float rotationSpeed = 0f;
[Export] public bool UseParentRotationOffset { get; set; } = false;
[Export] public float _rotationOffset = 0f;
[Export] public float duration = 5f;
[Export] public float spread = 360f;
@ -184,6 +185,12 @@ public partial class ShootingPattern3D : AttackPattern
Vector2 direction = pattern.BulletResource.Direction;
// Rotate with parent rotation
if (pattern.UseParentRotationOffset)
{
direction = direction.Rotated(-ScriptHost.ParentObject.GlobalRotation.Y + Mathf.DegToRad(90));
}
// TODO: Fix player aiming for 3D
if (pattern._targetPlayer && GameController.Instance.PlayerPosition.HasValue)
{

View file

@ -1,4 +1,5 @@
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Interactables._3D;
@ -28,6 +29,29 @@ public partial class AnimatedSwitch3D : Switch3D
SyncAnimation();
}
public override void _func_godot_apply_properties(Dictionary<string, Variant> props)
{
base._func_godot_apply_properties(props);
// TargetGroup = props["target"].AsString();
// if (props.TryGetValue("key", out var prop))
// {
// RequirementKeys = [prop.AsString()];
// }
// if (props.TryGetValue("activationtype", out var type))
// {
// var t = Enum.TryParse(type, true, out ActivationType activationType);
// if (t)
// {
// ActivationType = activationType;
// }
// }
var startEnabled = props["start_enabled"].AsBool();
State = startEnabled ? DoorState.Open : DoorState.Closed;
}
private void SyncAnimation()
{

View file

@ -9,7 +9,7 @@ namespace Cirno.Scripts.Interactables;
[Tool]
public partial class Switch3D : Interactable3D
{
[Export] public string TargetGroup { get; private set; }
[Export] public string TargetGroup { get; protected set; }
[Export] public Node Target { get; set; }
[Export] public Array<Node> Targets { get; private set; } = [];
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
@ -31,17 +31,17 @@ public partial class Switch3D : Interactable3D
_denySound = GetNodeOrNull<AudioStreamPlayer>(_denySoundName);
}
public void _func_godot_apply_properties(Dictionary<string, string> props)
public virtual void _func_godot_apply_properties(Dictionary<string, Variant> props)
{
TargetGroup = props["target"];
TargetGroup = props["target"].AsString();
if (props.TryGetValue("key", out var prop))
{
RequirementKeys = [prop];
RequirementKeys = [prop.AsString()];
}
if (props.TryGetValue("activationtype", out var type))
{
var t = Enum.TryParse(type, true, out ActivationType activationType);
var t = Enum.TryParse(type.AsString(), true, out ActivationType activationType);
if (t)
{
ActivationType = activationType;
@ -68,11 +68,11 @@ public partial class Switch3D : Interactable3D
if (!string.IsNullOrWhiteSpace(TargetGroup))
{
ActivationHelper.UseTargets(this, TargetGroup, activationType);
success |= ActivationHelper.UseTargets(this, TargetGroup, activationType);
}
var result = Targets.Aggregate(success,
(current, target) => ActivateTarget(target, activationTypeToUse) | success);
(current, target) => current | ActivateTarget(target, activationTypeToUse));
if (result)
{

View file

@ -4,8 +4,9 @@ namespace Cirno.Scripts.Utils;
public static class ActivationHelper
{
public static void UseTargets(Node activator, string target, ActivationType activationType = ActivationType.Toggle)
public static bool UseTargets(Node activator, string target, ActivationType activationType = ActivationType.Toggle)
{
var res = false;
GD.Print($"Trying to use targets called: {target}");
var targetList = activator.GetTree().GetNodesInGroup(target);
foreach (var t in targetList)
@ -15,8 +16,10 @@ public static class ActivationHelper
if (t is IActivable activable)
{
GD.Print($"Activating {t.Name}");
activable.Activate(activationType);
res |= activable.Activate(activationType);
}
}
return res;
}
}

View file

@ -332,9 +332,13 @@ public partial class Bullet3D : Area3D, IBullet
Destroy();
}
private readonly StringName SolidGroup = "Solid";
private readonly StringName PermeableGroup = "Permeable";
private readonly StringName DestroyableGroup = "Destroyable";
private void _on_body_entered(Node3D body)
{
if (body.IsInGroup("Destroyable") && body is IDestructible destructible &&
if (body.IsInGroup(DestroyableGroup) && body is IDestructible destructible &&
CanHit(BulletOwner, destructible.BulletGroup))
{
// hit
@ -344,7 +348,7 @@ public partial class Bullet3D : Area3D, IBullet
return;
}
if (body.IsInGroup("Solid"))
if (body.IsInGroup(SolidGroup) && !body.IsInGroup(PermeableGroup))
{
//Debug.WriteLine("Collision");
RequestCollisionDestruction();