Populate minigame with obstacles and monster spawns (#5)
- Simulated "fake" physics and collisions - Object pooling for tiles, obstacles and monster spawns - Base monster scoring with proximity triggers and depth multiplier Co-authored-by: AlexanderT <alexander@foolhardyhorizons.com> Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #5
This commit is contained in:
69
Assets/Scripts/DamianExperiments/LawnMowerChaseBehaviour.cs
Normal file
69
Assets/Scripts/DamianExperiments/LawnMowerChaseBehaviour.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
using Pixelplacement;
|
||||
|
||||
public class LawnMowerChaseBehaviour : MonoBehaviour
|
||||
{
|
||||
public Spline ChaseSpline;
|
||||
public Transform LawnMowerObject;
|
||||
public float chaseDuration;
|
||||
public float chaseDelay;
|
||||
|
||||
private Vector3 _originalScale;
|
||||
private bool _facingRight = true;
|
||||
private bool _movingForward = true;
|
||||
private float _lastPercentage = 0f;
|
||||
private const float AnchorThreshold = 0.1f; // Tolerance for anchor detection
|
||||
|
||||
void Start()
|
||||
{
|
||||
_originalScale = LawnMowerObject.localScale;
|
||||
|
||||
Tween.Spline(
|
||||
ChaseSpline,
|
||||
LawnMowerObject,
|
||||
0,
|
||||
1,
|
||||
false,
|
||||
chaseDuration,
|
||||
chaseDelay,
|
||||
Tween.EaseInOut,
|
||||
Tween.LoopType.PingPong,
|
||||
onComplete: OnTweenComplete
|
||||
);
|
||||
}
|
||||
|
||||
private void OnTweenComplete()
|
||||
{
|
||||
_movingForward = !_movingForward;
|
||||
Flip(_movingForward);
|
||||
}
|
||||
|
||||
private void OnTweenUpdate()
|
||||
{
|
||||
// Find the current percentage along the spline
|
||||
float percentage = ChaseSpline.ClosestPoint(LawnMowerObject.position);
|
||||
|
||||
// Detect anchor arrival and flip accordingly
|
||||
if (_facingRight && percentage >= 1f - AnchorThreshold)
|
||||
{
|
||||
Flip(false); // Face left at end anchor
|
||||
_facingRight = false;
|
||||
}
|
||||
else if (!_facingRight && percentage <= AnchorThreshold)
|
||||
{
|
||||
Flip(true); // Face right at start anchor
|
||||
_facingRight = true;
|
||||
}
|
||||
|
||||
_lastPercentage = percentage;
|
||||
}
|
||||
|
||||
private void Flip(bool faceRight)
|
||||
{
|
||||
var scale = _originalScale;
|
||||
scale.x = Mathf.Abs(scale.x) * (faceRight ? 1 : -1);
|
||||
LawnMowerObject.localScale = scale;
|
||||
}
|
||||
|
||||
void Update() { }
|
||||
}
|
||||
Reference in New Issue
Block a user