Added spring

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

View File

@@ -12,14 +12,14 @@ namespace Fruitomation.Game
private void Start()
{
TriggerDetector.SetAction((other) =>
TriggerDetector.SetAction(other =>
{
if (other.transform.parent.TryGetComponent(out Rigidbody2D body))
{
Vector3 force = new(-transform.localScale.x, 0f, 0f);
body?.AddForce(force * Mathf.PI, ForceMode2D.Impulse);
}
});
}, TriggerType.Stay);
}
private void Update()

View File

@@ -0,0 +1,7 @@
namespace Fruitomation.Game
{
public class SlicerBuilding : Building
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f2a0d2e92ab8436a8854e59ee269188a
timeCreated: 1776341863

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);
}
}
}

View File

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