Added the Flying Butterfly WIP

This commit is contained in:
2025-11-12 16:25:32 +01:00
parent 612ca7eae8
commit c3639bbb93
14 changed files with 4504 additions and 16 deletions

View File

@@ -0,0 +1,55 @@
using Pixelplacement;
using UnityEngine;
using Core.SaveLoad;
public class ButterFlyBehaviour : MonoBehaviour
{
public Spline butterflightSpline;
public Transform butterflyObject;
public float flightDuration = 2f;
public float flightDelay = 0f;
[Range(0, 1)] public float startPercentage = 0f;
private const float AnchorThreshold = 0.05f;
// Called when entering the butterfly flight state
public void OnEnterState()
{
if (butterflightSpline == null || butterflyObject == null)
{
Debug.LogWarning("ButterFlyBehaviour: Missing spline or butterfly object reference.");
return;
}
butterflyObject.position = butterflightSpline.GetPosition(startPercentage);
float distanceToStart = Mathf.Abs(startPercentage - 0f);
float distanceToEnd = Mathf.Abs(startPercentage - 1f);
float targetPercentage;
float duration;
if (distanceToStart < distanceToEnd)
{
targetPercentage = 1f;
duration = flightDuration * (1f - startPercentage);
}
else
{
targetPercentage = 0f;
duration = flightDuration * startPercentage;
}
Tween.Spline(
butterflightSpline,
butterflyObject,
startPercentage,
targetPercentage,
false,
duration,
flightDelay,
Tween.EaseInOut,
Tween.LoopType.None
);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f8cd0ca91dab0404daaa3fa1dc722658