mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-02 22:31:10 +00:00
fix: correct teleport radius
This commit is contained in:
@@ -9,37 +9,42 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
|
||||
{
|
||||
public class FindRandomPointForTeleportSystem : IInitializableSystem, IDisposableSystem
|
||||
{
|
||||
private Transform _target;
|
||||
private Transform _toPoint;
|
||||
|
||||
private ReactiveEvent _findPointRequest;
|
||||
private ReactiveEvent _findPointEvent;
|
||||
|
||||
|
||||
private ReactiveVariable<float> _radius;
|
||||
|
||||
private IDisposable _findPointRequestDisposable;
|
||||
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_target = entity.TeleportTarget;
|
||||
_toPoint = entity.TeleportToPoint;
|
||||
_radius = entity.TeleportSearchRadius;
|
||||
_findPointRequest = entity.FindTeleportPointRequest;
|
||||
_findPointEvent = entity.FindTeleportPointEvent;
|
||||
|
||||
|
||||
_findPointRequestDisposable = _findPointRequest.Subscribe(OnFindPointRequest);
|
||||
}
|
||||
|
||||
|
||||
public void OnDispose()
|
||||
{
|
||||
_findPointRequestDisposable.Dispose();
|
||||
}
|
||||
|
||||
|
||||
private void OnFindPointRequest()
|
||||
{
|
||||
_toPoint.position = GetRandomPointByRadius(_radius.Value);
|
||||
_toPoint.position = GetRandomPointInRadius(_target.position, _radius.Value);
|
||||
_findPointEvent.Invoke();
|
||||
}
|
||||
|
||||
private Vector3 GetRandomPointByRadius(float radius)
|
||||
=> new(Random.Range(0, radius), 0, Random.Range(0, radius));
|
||||
|
||||
private Vector3 GetRandomPointInRadius(Vector3 center, float radius)
|
||||
{
|
||||
Vector2 randomPoint = Random.insideUnitCircle * radius;
|
||||
return center + new Vector3(randomPoint.x, 0f, randomPoint.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user