Added the Flying Butterfly WIP
This commit is contained in:
55
Assets/Scripts/DamianExperiments/ButterFlyBehaviour.cs
Normal file
55
Assets/Scripts/DamianExperiments/ButterFlyBehaviour.cs
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8cd0ca91dab0404daaa3fa1dc722658
|
||||
Reference in New Issue
Block a user