mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 01:15:53 +00:00
3D bullet rotation
This commit is contained in:
parent
4541c5fbf4
commit
1a455251a9
43 changed files with 279 additions and 203 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Cirno.Scripts.Enums;
|
||||
using Cirno.Scripts.Components.Actors;
|
||||
using Cirno.Scripts.Enums;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Enemy._3D;
|
||||
|
|
@ -10,6 +11,8 @@ public partial class Init : EnemyStateBase3D
|
|||
|
||||
[Export] public PlayerDetection3D DetectionProvider { get; private set; }
|
||||
|
||||
[Export] public ActorResourceProvider HealthProvider { get; private set; }
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
//DamageReceiver.HealthProvider.MaxResource = StorageModule.Root.EnemyResource.MaxHealth;
|
||||
|
|
@ -19,6 +22,10 @@ public partial class Init : EnemyStateBase3D
|
|||
Storage.HomePosition = MainObject.GlobalPosition;
|
||||
// TODO: Hide wings
|
||||
// TODO: Hide aiming reticule
|
||||
|
||||
HealthProvider.MaxResource = Storage.Root.EnemyResource.MaxHealth;
|
||||
|
||||
HealthProvider.FillResource();
|
||||
|
||||
StateMachine.SetState(EnemyState.Idle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Components;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
|
|
@ -12,6 +13,8 @@ public partial class BulletResource : Resource
|
|||
{
|
||||
[Export]
|
||||
public PackedScene BulletScene { get; set; }
|
||||
[Export] public Texture2D BulletSprite { get; set; }
|
||||
[Export] public float BulletSize { get; set; }
|
||||
[Export] public PackedScene DestructionParticlesScene { get; set; }
|
||||
[Export] public float BulletSpeed = 100f;
|
||||
[Export] public Vector2 Direction = Vector2.Right;
|
||||
|
|
@ -19,13 +22,8 @@ public partial class BulletResource : Resource
|
|||
[Export] public float MaxDamage = 1;
|
||||
[Export] public float Knockback = 1;
|
||||
[Export] public float LifeTime = 10f;
|
||||
[Export] public bool DestroyOnCollision = true;
|
||||
[Export] public BulletOwner Owner = BulletOwner.None;
|
||||
[Export] public DamageType DamageType = DamageType.Neutral;
|
||||
[Export] public bool RotateSprite = false;
|
||||
[Export] public bool Controllable = false;
|
||||
[Export] public bool Freezable { get; set; } = true;
|
||||
[Export] public bool Grazeable { get; set; } = true;
|
||||
[Export] public float GrazeValue { get; set; } = 0.2f;
|
||||
|
||||
[Export] public BulletFlags Attributes { get; set; }
|
||||
|
|
@ -51,13 +49,13 @@ public partial class BulletResource : Resource
|
|||
RotationOffset = rotationOffset,
|
||||
Modifier = Modifier,
|
||||
LifeTime = LifeTime,
|
||||
DestroyOnCollision = DestroyOnCollision,
|
||||
DestroyOnCollision = Attributes.HasNoFlags(BulletFlags.Piercing),
|
||||
DestructionParticlesScene = DestructionParticlesScene,
|
||||
RotateSprite = RotateSprite,
|
||||
Controllabe = Controllable,
|
||||
Freezable = Freezable,
|
||||
RotateSprite = Attributes.HasFlag(BulletFlags.Rotateable),
|
||||
Controllabe = Attributes.HasFlag(BulletFlags.Controllable),
|
||||
Freezable = Attributes.HasFlag(BulletFlags.Freezable),
|
||||
TimeModifiers = TimeModifiers.Select(x => x).ToList(),
|
||||
Grazeable = Grazeable,
|
||||
Grazeable = Attributes.HasFlag(BulletFlags.Grazeable),
|
||||
GrazeValue = GrazeValue,
|
||||
Attributes = Attributes,
|
||||
// TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().Select(m => new ModifierWrapper()
|
||||
|
|
|
|||
|
|
@ -45,23 +45,45 @@ public partial class Bullet3D : Area3D, IBullet
|
|||
|
||||
private CollisionShape3D _collisionShape;
|
||||
|
||||
private Sprite3D _sprite;
|
||||
|
||||
private readonly Vector3 _defaultRotation = new(
|
||||
Mathf.DegToRad(-45f),
|
||||
Mathf.DegToRad(45f),
|
||||
0f
|
||||
);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_grazeSound = GetNodeOrNull<AudioStreamPlayer3D>("AudioStreamPlayer");
|
||||
_grazeParticles = GetNodeOrNull<GpuParticles3D>("GrazeParticles");
|
||||
|
||||
_collisionShape = GetNode<CollisionShape3D>("CollisionShape");
|
||||
|
||||
_sprite = GetNodeOrNull<Sprite3D>("Sprite");
|
||||
}
|
||||
|
||||
public void Initialize(BulletInfo bulletInfo)
|
||||
{
|
||||
_bulletInfo = bulletInfo;
|
||||
|
||||
|
||||
_elapsedTime = 0f;
|
||||
|
||||
this.Speed = bulletInfo.Speed;
|
||||
|
||||
_sprite?.SetRotation(_defaultRotation);
|
||||
SpriteRotation = 0f;
|
||||
|
||||
if (_sprite is not null && bulletInfo.OriginalBulletResource.BulletSprite is not null)
|
||||
{
|
||||
_sprite.Texture = _bulletInfo.OriginalBulletResource.BulletSprite;
|
||||
}
|
||||
|
||||
if (_collisionShape.Shape is SphereShape3D sphere && bulletInfo.OriginalBulletResource.BulletSize > 0)
|
||||
{
|
||||
sphere.Radius = bulletInfo.OriginalBulletResource.BulletSize;
|
||||
}
|
||||
|
||||
// Need to clone them here
|
||||
// _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList();
|
||||
|
||||
|
|
@ -151,7 +173,7 @@ public partial class Bullet3D : Area3D, IBullet
|
|||
_direction = _direction.Rotated(radians).Normalized(); // Rotate direction
|
||||
|
||||
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
|
||||
RotateSprite(SpriteRotation + radians);
|
||||
RotateSprite(SpriteRotation + radians + Mathf.DegToRad(45));
|
||||
//SetRotation(Rotation + radians);
|
||||
}
|
||||
|
||||
|
|
@ -169,15 +191,14 @@ public partial class Bullet3D : Area3D, IBullet
|
|||
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
|
||||
SpriteRotation += radians;
|
||||
|
||||
Vector3 axis = Basis.FromEuler(new Vector3(
|
||||
Mathf.DegToRad(-45f),
|
||||
Mathf.DegToRad(45f),
|
||||
0f
|
||||
)).Z;
|
||||
|
||||
Rotate(axis, radians);
|
||||
|
||||
var axis = Basis.FromEuler(_defaultRotation).Z;
|
||||
_sprite?.Rotate(axis, radians);
|
||||
//_sprite.SetRotation(new Vector3());
|
||||
//Rotate(axis, radians);
|
||||
//_sprite?.Rotate(Vector3.Forward, radians);
|
||||
//_sprite?.RotateZ(radians);
|
||||
//SetRotation(Rotation + radians);
|
||||
|
||||
}
|
||||
|
||||
public void FacePlayer()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue