WIP Butterfly can be set free, now only missing forcing the couple to look.

This commit is contained in:
2025-11-13 16:23:52 +01:00
parent c3639bbb93
commit c08fc4a720
6 changed files with 196 additions and 66 deletions

View File

@@ -4,52 +4,50 @@ using Core.SaveLoad;
public class ButterFlyBehaviour : MonoBehaviour
{
public AppleMachine butterStateMachine;
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;
private Animator butterflyAnimator;
// Called when entering the butterfly flight state
public void OnEnterState()
public void OnEnable()
{
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)
if (butterflyObject != null )
{
targetPercentage = 1f;
duration = flightDuration * (1f - startPercentage);
}
else
{
targetPercentage = 0f;
duration = flightDuration * startPercentage;
butterflyAnimator = butterflyObject.GetComponentInChildren<Animator>();
}
butterflyAnimator.SetTrigger("BrokeOut");
Tween.Spline(
butterflightSpline,
butterflyObject,
startPercentage,
targetPercentage,
0,
1,
false,
duration,
flightDuration,
flightDelay,
Tween.EaseInOut,
Tween.LoopType.None
Tween.LoopType.None, HandleTweenStarted, HandleTweenFinished
);
}
public void HandleTweenStarted()
{
}
public void HandleTweenFinished()
{
butterStateMachine.ChangeState("Free");
}
}

View File

@@ -0,0 +1,13 @@
using Core.SaveLoad;
using Core;
using UnityEngine;
public class ButterFlyState : AppleMachine
{
public void stateSwitch(string StateName)
{
Logging.Debug("State Switch to: " + StateName);
ChangeState(StateName);
}
}

View File

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

View File

@@ -0,0 +1,19 @@
using Pixelplacement;
using UnityEngine;
using Core.SaveLoad;
public class ButterflyFreeBehaviour : MonoBehaviour
{
public GameObject butterflyRef;
private Animator butterflyAnimator;
public void OnEnable()
{
if (butterflyRef != null)
{
butterflyAnimator = butterflyRef.GetComponentInChildren<Animator>();
}
butterflyAnimator.SetTrigger("IsFree");
Debug.Log("ButterflyFreeBehaviour enabled");
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6821f70f6ac4b85418b15ce068ddc6da