mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 01:45:54 +00:00
Basic weapon direction
This commit is contained in:
parent
9362f66fdf
commit
0146de8ab5
4 changed files with 92 additions and 6 deletions
|
|
@ -6,7 +6,7 @@ using Cirno.Scripts.Components;
|
|||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Utils;
|
||||
|
||||
public partial class Weapon : Sprite2D
|
||||
public partial class Weapon : Node2D
|
||||
{
|
||||
|
||||
[Export]
|
||||
|
|
@ -18,6 +18,12 @@ public partial class Weapon : Sprite2D
|
|||
[Export]
|
||||
public Marker2D Muzzle { get; set; }
|
||||
|
||||
[Export]
|
||||
public Marker2D Pivot { get; set; }
|
||||
|
||||
[Export]
|
||||
public Sprite2D Sprite { get; private set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void ShootingEventHandler();
|
||||
|
||||
|
|
@ -189,4 +195,42 @@ public partial class Weapon : Sprite2D
|
|||
|
||||
_cooldownTimer.Start(WeaponData?.RateOfFire ?? 0);
|
||||
}
|
||||
|
||||
public void RotateWeapon(Vector2 facingDirection, Vector2 leftPosition, Vector2 rightPosition)
|
||||
{
|
||||
bool facingLeft = facingDirection.X < 0;
|
||||
|
||||
if (facingLeft)
|
||||
{
|
||||
Sprite.Position = leftPosition - Pivot.Position;
|
||||
Sprite.FlipH = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Sprite.Position = rightPosition - Pivot.Position;
|
||||
Sprite.FlipH = false;
|
||||
}
|
||||
|
||||
// var angle = Mathf.Atan2(StorageModule.FacingDirection.X, StorageModule.FacingDirection.Y);
|
||||
//
|
||||
// // Weapon is drawn pointing right, but we want it to point "up" along aim vector.
|
||||
// // So we apply a 90° offset (π/2), but...
|
||||
// // If facing left, we also add 180° (π) to "un-mirror" it visually.
|
||||
// float rotationOffset = (Mathf.Pi / 2f);
|
||||
//
|
||||
// if (facingLeft)
|
||||
// {
|
||||
// EquippedWeapon.Sprite.Rotation = -(angle + rotationOffset);// + rotationOffset + Mathf.Pi;
|
||||
// EquippedWeapon.Sprite.Position = WeaponLeftOffset;
|
||||
// EquippedWeapon.Sprite.FlipH = true; // disable FlipH to avoid messing with rotation
|
||||
// EquippedWeapon.Sprite.FlipV = false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// EquippedWeapon.Sprite.Rotation = angle;// + rotationOffset;
|
||||
// EquippedWeapon.Sprite.Position = WeaponRightOffset;
|
||||
// EquippedWeapon.Sprite.FlipH = false;
|
||||
// EquippedWeapon.Sprite.FlipV = true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue