basic projectiles
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 26s
Create tag and build when new code gets to main / Export (push) Successful in 5m9s

This commit is contained in:
2026-05-07 14:53:30 +02:00
parent 01a2e7582b
commit 150e007b22
13 changed files with 504 additions and 32 deletions

View File

@@ -0,0 +1,124 @@
using Godot;
using System;
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Gamesmiths.Forge.Abilities;
using Gamesmiths.Forge.Core;
using Gamesmiths.Forge.Cues;
using Gamesmiths.Forge.Effects;
using Gamesmiths.Forge.Events;
using Gamesmiths.Forge.Godot.Resources.Abilities;
using Gamesmiths.Forge.Statescript;
using Gamesmiths.Forge.Tags;
using Movementtests.interfaces;
using Movementtests.tools;
using Node = Godot.Node;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_bullet.png"), Meta(typeof(IAutoNode))]
public partial class Projectile : RigidBody3D, IForgeEntity, ITargetable, IKillable, ISpawnable
{
public override void _Notification(int what) => this.Notify(what);
#region Dependencies
[Dependency]
public TagsManager TagsManager => this.DependOn<TagsManager>();
[Dependency]
public CuesManager CuesManager => this.DependOn<CuesManager>();
#endregion
#region IForgeEntity
// Perfectly forward the IForgeEntity interface to the ForgeEntity component
public EntityAttributes Attributes
{
get => ForgeEntity.Attributes;
set => ForgeEntity.Attributes = value;
}
public EntityTags Tags
{
get => ForgeEntity.Tags;
set => ForgeEntity.Tags = value;
}
public EffectsManager EffectsManager
{
get => ForgeEntity.EffectsManager;
set => ForgeEntity.EffectsManager = value;
}
public EntityAbilities Abilities
{
get => ForgeEntity.Abilities;
set => ForgeEntity.Abilities = value;
}
public EventManager Events
{
get => ForgeEntity.Events;
set => ForgeEntity.Events = value;
}
public Variables SharedVariables
{
get => ForgeEntity.SharedVariables;
set => ForgeEntity.SharedVariables = value;
}
#endregion
[Node("ForgeEntityNode")] public required ForgeEntityNode ForgeEntity { get; set;}
[Export] public float Damage = 10f;
public Node3D Target { get; set; }
public void Init()
{
ApplyCentralImpulse(Vector3.Up * 10);
}
public override void _IntegrateForces(PhysicsDirectBodyState3D state)
{
var direction = GlobalPosition.DirectionTo(Target.GlobalPosition);
state.LinearVelocity += direction / 10.0f;
}
public void OnResolved()
{
BodyEntered += OnProjectileHit;
// Events.Subscribe(Tag.RequestTag(TagsManager, "events.weapon.flyingtick"), data => { GD.Print("tick"); });
}
private void OnProjectileHit(Node body)
{
if (body is IForgeEntity entity)
{
Events.Raise(new EventData
{
EventTags = Tag.RequestTag(TagsManager, "events.combat.hit").GetSingleTagContainer()!,
Source = this,
Target = entity,
EventMagnitude = Damage
});
}
Events.Raise(new EventData
{
EventTags = Tag.RequestTag(TagsManager, "events.weapon.planted").GetSingleTagContainer()!,
Source = this,
EventMagnitude = Damage
});
Kill();
}
public Vector3 GetTargetGlobalPosition()
{
return GlobalPosition;
}
public void Kill()
{
QueueFree(); // If thrown offmap
}
}