Gegner Schaden an Base, fertiges Pathing und Wechseln zu anderen Base-Ebenen (Modular erweiterbar wenn nötig). Nächster Schritt ist Wackeln in Gegnerbewegung zu entfernen und mehr Combat. Bei Spiel Verloren noch nicht pausiert weil Game Over Screen noch nicht vorhanden.
This commit is contained in:
1 parent
99d6ddee26
commit
caebc2c179
25 files changed
+2678
-1335
No files matched your search
@@ -114,4 +114,156 @@ public class CharacterRotation : MonoBehaviour
|
||||
targetAngle
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
[Header("Visual")]
|
||||
[SerializeField]
|
||||
private Transform visual;
|
||||
|
||||
[Header("Rotation")]
|
||||
[SerializeField]
|
||||
private float maxRotationSpeed = 720f;
|
||||
|
||||
[SerializeField]
|
||||
private float rotationAcceleration = 3f;
|
||||
|
||||
[Tooltip("Ab welcher Winkeländerung eine neue Drehung erkannt wird.")]
|
||||
[SerializeField]
|
||||
private float directionChangeThreshold = 5f;
|
||||
|
||||
[Tooltip("In welche lokale Richtung zeigt die Grafik standardmäßig?")]
|
||||
[SerializeField]
|
||||
private SpriteForwardDirection spriteForward =
|
||||
SpriteForwardDirection.Up;
|
||||
|
||||
private IMovementDirection movement;
|
||||
|
||||
private float rotationTime = 0f;
|
||||
|
||||
private Quaternion lastTargetRotation;
|
||||
private bool hasLastTargetRotation = false;
|
||||
|
||||
private enum SpriteForwardDirection
|
||||
{
|
||||
Up,
|
||||
Right
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
movement = GetComponent<IMovementDirection>();
|
||||
|
||||
if (movement == null)
|
||||
{
|
||||
Debug.LogError(
|
||||
"CharacterRotation benötigt eine Komponente, " +
|
||||
"die IMovementDirection implementiert.",
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
if (visual == null)
|
||||
{
|
||||
Debug.LogError(
|
||||
"CharacterRotation: Kein Visual zugewiesen.",
|
||||
this
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (movement == null || visual == null)
|
||||
return;
|
||||
|
||||
Vector2 direction = movement.MovementDirection;
|
||||
|
||||
// Keine Bewegung -> aktuelle Rotation behalten.
|
||||
if (direction.sqrMagnitude < 0.001f)
|
||||
return;
|
||||
|
||||
RotateTowards(direction);
|
||||
}
|
||||
|
||||
// ROTATIONSLOGIK
|
||||
|
||||
public void SetInitialRotation()
|
||||
{
|
||||
if (movement == null || visual == null)
|
||||
return;
|
||||
|
||||
Vector2 direction = movement.MovementDirection;
|
||||
|
||||
if (direction.sqrMagnitude < 0.001f)
|
||||
return;
|
||||
|
||||
Quaternion targetRotation = GetTargetRotation(direction);
|
||||
|
||||
visual.rotation = targetRotation;
|
||||
|
||||
rotationTime = 0f;
|
||||
lastTargetRotation = targetRotation;
|
||||
hasLastTargetRotation = true;
|
||||
}
|
||||
|
||||
private void RotateTowards(Vector2 direction)
|
||||
{
|
||||
Quaternion targetRotation = GetTargetRotation(direction);
|
||||
|
||||
// Prüfen, ob sich die Zielrichtung geändert hat.
|
||||
if (!hasLastTargetRotation ||
|
||||
Quaternion.Angle(lastTargetRotation, targetRotation)
|
||||
> directionChangeThreshold)
|
||||
{
|
||||
rotationTime = 0f;
|
||||
lastTargetRotation = targetRotation;
|
||||
hasLastTargetRotation = true;
|
||||
}
|
||||
|
||||
// Drehdauer erhöhen.
|
||||
rotationTime += Time.deltaTime;
|
||||
|
||||
// Exponentielle Beschleunigung.
|
||||
float speed =
|
||||
maxRotationSpeed *
|
||||
(1f - Mathf.Exp(-rotationAcceleration * rotationTime));
|
||||
|
||||
// Rotation durchführen.
|
||||
visual.rotation =
|
||||
Quaternion.RotateTowards(
|
||||
visual.rotation,
|
||||
targetRotation,
|
||||
speed * Time.deltaTime
|
||||
);
|
||||
|
||||
// Drehung abgeschlossen?
|
||||
if (Quaternion.Angle(
|
||||
visual.rotation,
|
||||
targetRotation
|
||||
) < 0.1f)
|
||||
{
|
||||
rotationTime = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
private Quaternion GetTargetRotation(Vector2 direction)
|
||||
{
|
||||
float targetAngle =
|
||||
Mathf.Atan2(
|
||||
direction.y,
|
||||
direction.x
|
||||
) * Mathf.Rad2Deg;
|
||||
|
||||
if (spriteForward == SpriteForwardDirection.Up)
|
||||
{
|
||||
targetAngle -= 90f;
|
||||
}
|
||||
|
||||
return Quaternion.Euler(
|
||||
0f,
|
||||
0f,
|
||||
targetAngle
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in new issue
Block a user