private void TickArrivals() { ListX <TransformInfo> transformInfos = GameData.Instance.transformInfoMap; float startDistanceSquared = arrivalHyperspaceDistance * arrivalHyperspaceDistance; float arrivalThresholdSquared = arrivedThreshold * arrivedThreshold; float deltaTime = GameTimer.Instance.deltaTime; int count = arrivals.Count; for (int i = 0; i < count; i++) { Arrival arrival = arrivals[i]; TransformInfo entityTransform = transformInfos[arrival.entityId]; float distRatio = entityTransform.DistanceToSquared(arrival.startPoint) / startDistanceSquared; float speed = arrivalSpeedCurve.Evaluate(Mathf.Clamp01(distRatio)) * hyperspaceEnterSpeed; entityTransform.position += (entityTransform.forward * speed) * deltaTime; float distSqr = entityTransform.DistanceToSquared(arrival.startPoint); if (distSqr >= arrivalThresholdSquared) { Trigger(new Evt_EntityArrived(arrival.entityId)); } transformInfos[arrival.entityId] = entityTransform; } }
private void TickDepartures() { ListX <TransformInfo> transformInfos = GameData.Instance.transformInfoMap; float endDistanceSquared = departureHyperspaceDistance * departureHyperspaceDistance; float deltaTime = GameTimer.Instance.deltaTime; int count = departures.Count; for (int i = 0; i < count; i++) { Departure departure = departures[i]; TransformInfo entityTransform = transformInfos[departure.entityId]; float distRatio = 1f - (entityTransform.DistanceToSquared(departure.endPoint) / endDistanceSquared); // todo -- first accelerate to top speed, then add speed + this computed speed float speed = (departureSpeedCurve.Evaluate(Mathf.Clamp01(distRatio)) * hyperspaceExitSpeed); entityTransform.position += (entityTransform.forward * speed) * deltaTime; Vector3 toTarget = (departure.endPoint - entityTransform.position).normalized; if ((Vector3.Dot(toTarget, entityTransform.forward) < 0)) { Trigger(new Evt_EntityDeparted(departure.entityId)); } transformInfos[departure.entityId] = entityTransform; } }