Added spring

This commit is contained in:
Pasha Bibko
2026-04-16 13:22:52 +01:00
parent 6868788af7
commit e515ce1dc1
16 changed files with 640 additions and 37 deletions

View File

@@ -0,0 +1,35 @@
using UnityEngine;
using System;
namespace Fruitomation.Game
{
public class SpringBuilding : Building
{
[SerializeField] private TriggerDetector Trigger;
private void Start()
{
Trigger.SetAction(other =>
{
if (other.transform.parent.TryGetComponent(out Rigidbody2D body))
{
Vector2 v0 = body.linearVelocity;
float magnitude = Math.Max(v0.magnitude * 0.8f, 20f);
Vector2 v1 = new Vector2(v0.x * 1.2f, Math.Abs(v0.y)).normalized * magnitude;
body.linearVelocity = v1;
}
}, TriggerType.Enter);
Trigger.SetAction(other =>
{
if (other.transform.parent.TryGetComponent(out Rigidbody2D body))
{
Vector2 v0 = body.linearVelocity;
v0.y = Math.Max(1f, v0.y);
body.linearVelocity = v0;
}
}, TriggerType.Stay);
}
}
}