Mapping and direction code

This commit is contained in:
Marco 2025-09-25 10:25:10 +02:00
commit 944249d408
26 changed files with 1453 additions and 536 deletions

View file

@ -126,20 +126,36 @@ public partial class Bullet3D : Area3D, IBullet
private Vector3 MakeRotationFromDirection(Vector2 direction)
{
// Rotate input by -45 degrees to counter camera isometry
float cos = Mathf.Cos(-Mathf.Pi / 4f);
float sin = Mathf.Sin(-Mathf.Pi / 4f);
// atan2 gives angle in radians around Z
float zRotation2 = Mathf.Atan2(-direction.Y, direction.X) + Mathf.Pi;
Vector2 rotatedDir = new Vector2(
direction.X * cos - direction.Y * sin,
direction.X * sin + direction.Y * cos
// Apply correction for your sprite's local forward axis
zRotation2 += Mathf.DegToRad(45f); // tweak to +45 or -45 as needed
return new Vector3(
Mathf.DegToRad(-45f), // X tilt (to match camera)
Mathf.DegToRad(45f), // Y tilt (to match camera)
zRotation2 // Facing direction
);
//float zRotation = Mathf.Atan2(rotatedDir.Y, rotatedDir.X)/* - Mathf.Pi / 2f*/;
float zRotation = Mathf.Atan2(-rotatedDir.Y, rotatedDir.X) + Mathf.Pi;
return MakeRotationVectorRad(zRotation);
// var rotatedVector = direction.Rotated(Mathf.DegToRad(-45));
// var asrt = Vector2.ang
// return MakeRotationVectorRad(zRotation);
// Rotate input by -45 degrees to counter camera isometry
// float cos = Mathf.Cos(-Mathf.Pi / 4f);
// float sin = Mathf.Sin(-Mathf.Pi / 4f);
//
// Vector2 rotatedDir = new Vector2(
// direction.X * cos - direction.Y * sin,
// direction.X * sin + direction.Y * cos
// );
//
// //float zRotation = Mathf.Atan2(rotatedDir.Y, rotatedDir.X)/* - Mathf.Pi / 2f*/;
//
// float zRotation = Mathf.Atan2(-rotatedDir.Y, rotatedDir.X) + Mathf.Pi;
// var zRotationDegrees = Mathf.RadToDeg(zRotation);
// return MakeRotationVectorRad(zRotation);
}
/// <summary>