mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:45:33 +00:00
Bullet spawners in editor and bullets come out at the spanwer position
This commit is contained in:
parent
e2b9cc8c90
commit
b64e096661
16 changed files with 288 additions and 169 deletions
|
|
@ -2,9 +2,11 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Resources.BulletScripts;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Actors;
|
||||
|
||||
[Tool]
|
||||
public partial class ScriptableBulletsEmitter3D : Node3D, IActivable, IScriptHost3D
|
||||
{
|
||||
public Node3D ParentObject => this;
|
||||
|
|
@ -31,6 +33,7 @@ public partial class ScriptableBulletsEmitter3D : Node3D, IActivable, IScriptHos
|
|||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
//_scriptInstance = Script.Duplicate(true) as BulletScript;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(ActivationGroup))
|
||||
|
|
@ -49,9 +52,23 @@ public partial class ScriptableBulletsEmitter3D : Node3D, IActivable, IScriptHos
|
|||
}
|
||||
EmitSignal(SignalName.StateChanged, _isActive);
|
||||
}
|
||||
|
||||
public virtual void _func_godot_apply_properties(Dictionary<string, Variant> props)
|
||||
{
|
||||
ActivationGroup = props["targetname"].AsString();
|
||||
|
||||
var scriptPath = props["script_path"].AsString();
|
||||
Script = GD.Load<BulletScript3D>(scriptPath);
|
||||
|
||||
EmitOnStart = props["emit_on_start"].AsBool();
|
||||
InvertSignal = props["invert_signal"].AsBool();
|
||||
//TargetFunc = props["targetfunc"];
|
||||
//TargetName = props["targetname"];
|
||||
}
|
||||
|
||||
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
if (Engine.IsEditorHint()) return false;
|
||||
switch (activationType)
|
||||
{
|
||||
case ActivationType.Use:
|
||||
|
|
@ -89,6 +106,7 @@ public partial class ScriptableBulletsEmitter3D : Node3D, IActivable, IScriptHos
|
|||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
if (!_isActive) return;
|
||||
|
||||
ScriptMachine.UpdatePhase(delta);
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ public partial class ShootingPattern3D : AttackPattern
|
|||
// Rotate with parent rotation
|
||||
if (pattern.UseParentRotationOffset)
|
||||
{
|
||||
direction = direction.Rotated(-ScriptHost.ParentObject.GlobalRotation.Y + Mathf.DegToRad(90));
|
||||
direction = direction.Rotated(-spawner.GlobalRotation.Y + Mathf.DegToRad(90));
|
||||
}
|
||||
|
||||
// TODO: Fix player aiming for 3D
|
||||
|
|
@ -196,21 +196,21 @@ public partial class ShootingPattern3D : AttackPattern
|
|||
{
|
||||
if (pattern._predictPlayer && GameController.Instance.PlayerVelocity.HasValue)
|
||||
{
|
||||
var predictedDirection = MathFunctions.PredictInterceptPosition(ScriptHost.ParentObject.GlobalPosition.ToVector2(),
|
||||
var predictedDirection = MathFunctions.PredictInterceptPosition(spawner.GlobalPosition.ToVector2(),
|
||||
GameController.Instance.PlayerPosition.Value.ToVector2(), GameController.Instance.PlayerVelocity.Value.ToVector2(),
|
||||
pattern.BulletResource.BulletSpeed);
|
||||
if (predictedDirection.HasValue)
|
||||
{
|
||||
direction = (predictedDirection.Value - ScriptHost.ParentObject.GlobalPosition.ToVector2()).Normalized();
|
||||
direction = (predictedDirection.Value - spawner.GlobalPosition.ToVector2()).Normalized();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = (GameController.Instance.PlayerPosition.Value.ToVector2() - ScriptHost.ParentObject.GlobalPosition.ToVector2()).Normalized();
|
||||
direction = (GameController.Instance.PlayerPosition.Value.ToVector2() - spawner.GlobalPosition.ToVector2()).Normalized();
|
||||
}
|
||||
}
|
||||
|
||||
var spawnPosition = ScriptHost.ParentObject.GlobalPosition + pattern.EmitterOffset;
|
||||
var spawnPosition = spawner.GlobalPosition + pattern.EmitterOffset;
|
||||
|
||||
var bullet = pattern.MakeBullet(spawnPosition.ToVector2(), pattern.bulletCount,
|
||||
pattern.spread, angleOffset);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue