private void Interpolate(ClientBulletMono clientBullet, float deltaTime) { var targetInterpolationPoint = clientBullet.TargetPositions.First().Position; var currentInterpolationPoint = (Vector2)clientBullet.ObjectTransform.position; //check that we don't reach target var toTargetSqrDistance = (targetInterpolationPoint - currentInterpolationPoint).sqrMagnitude; var currentMovementMagnitude = clientBullet.ServerSpeed * deltaTime; if (toTargetSqrDistance < currentMovementMagnitude * currentMovementMagnitude) { //pop target as current location ExtractNewCurrentPosition(clientBullet); //if it was last traget kill client bullet if (clientBullet.IsReachedServerDeathPoint) { clientBullet.ObjectTransform.position = targetInterpolationPoint; clientBullet.gameObject.SetActive(false); clientBullet.IsDead = true; } else { Extrapolate(clientBullet, deltaTime); } return; } //move bullet to target var movementVector = (targetInterpolationPoint - currentInterpolationPoint).normalized * currentMovementMagnitude; clientBullet.ObjectTransform.position = currentInterpolationPoint + movementVector; }
public void ClientCall(ClientBulletMono clientBullet) { //check if only start of movement if (clientBullet.CurrentPosition == null) { //waiting first two point to interpolate if (clientBullet.TargetPositions.Count < 2) { return; } //find first two point to interpolate while (clientBullet.TargetPositions.Count > 1) { ExtractNewCurrentPosition(clientBullet); } //start interpolation var targetPoint = clientBullet.TargetPositions.First().Position; var currentPoint = clientBullet.CurrentPosition.Position; clientBullet.ClientSpeed = (targetPoint - currentPoint).magnitude / TickDuration; } //update current and target while (clientBullet.TargetPositions.Count > 1) { ExtractNewCurrentPosition(clientBullet); } }
public void UpdateCall(ClientBulletMono clientBullet, float deltaTime) { //no need visual update if (clientBullet.CurrentPosition == null || clientBullet.IsDead) { return; } //on extrapolation only start if (!clientBullet.IsLaunched) { clientBullet.IsLaunched = true; clientBullet.gameObject.SetActive(true); clientBullet.ObjectTransform.position = clientBullet.CurrentPosition.Position; return; } //on extrapolation finished if (clientBullet.IsReachedServerDeathPoint) { clientBullet.gameObject.SetActive(false); clientBullet.IsDead = true; return; } //on extrapolation var currentMovementVector = (Vector3)clientBullet.ServerVelocity.normalized * (clientBullet.ServerSpeed * deltaTime); clientBullet.ObjectTransform.position = clientBullet.ObjectTransform.position + currentMovementVector; }
public void ClientCall(ClientBulletMono clientBullet) { //check if only start of movement if (clientBullet.CurrentPosition == null) { //waiting first point to extrapolation if (clientBullet.TargetPositions.Count < 1) { return; } //find first point to extrapolation ExtractNewCurrentPosition(clientBullet); return; } //check that we alive if start movement if (clientBullet.IsLaunched) { while (clientBullet.TargetPositions.Count > 0) { ExtractNewCurrentPosition(clientBullet); } } }
public void UpdateCall(ClientBulletMono clientBullet, float deltaTime) { //no need visual update if (clientBullet.CurrentPosition == null || clientBullet.TargetPositions.Count == 0 || clientBullet.IsDead) { return; } //on interpolation only start if (!clientBullet.IsLaunched) { clientBullet.IsLaunched = true; clientBullet.gameObject.SetActive(true); clientBullet.ObjectTransform.position = clientBullet.CurrentPosition.Position; return; } var startInterpolationPoint = clientBullet.CurrentPosition.Position; var targetInterpolationPoint = clientBullet.TargetPositions.First().Position; var currentInterpolationPoint = (Vector2)clientBullet.ObjectTransform.position; //check that we do not need teleport var toTargetSqrDistance = (targetInterpolationPoint - currentInterpolationPoint).sqrMagnitude; var interpolationSqrDistance = (targetInterpolationPoint - startInterpolationPoint).sqrMagnitude; if (toTargetSqrDistance > interpolationSqrDistance) { var allowedDelay = TickDuration * TeleportIfDelayMoreThanTickPercent * clientBullet.ServerSpeed; var toStartSqrDistance = (startInterpolationPoint - currentInterpolationPoint).sqrMagnitude; if (toStartSqrDistance > allowedDelay * allowedDelay) { clientBullet.ObjectTransform.position = startInterpolationPoint; return; } } //check that we don't reach target var currentMovementMagnitude = deltaTime * clientBullet.ServerSpeed; if (toTargetSqrDistance < currentMovementMagnitude * currentMovementMagnitude) { //if no other target put bullet on last known target clientBullet.ObjectTransform.position = targetInterpolationPoint; //if it was last traget kill client bullet if (clientBullet.IsReachedServerDeathPoint) { clientBullet.gameObject.SetActive(false); clientBullet.IsDead = true; } return; } //move bullet to target var movementVector = (targetInterpolationPoint - currentInterpolationPoint).normalized * currentMovementMagnitude; clientBullet.ObjectTransform.position = currentInterpolationPoint + movementVector; }
private static void ExtractNewCurrentPosition(ClientBulletMono clientBullet) { if (clientBullet.CurrentPosition != null) { clientBullet.PassedPositions.Enqueue(clientBullet.CurrentPosition); } clientBullet.CurrentPosition = clientBullet.TargetPositions.Dequeue(); if (clientBullet.CurrentPosition.IsFinishedPosition) { clientBullet.IsReachedServerDeathPoint = true; } }
public void ClientCall(ClientBulletMono clientBullet) { while (clientBullet.TargetPositions.Count > 0) { var newCurrentPosition = clientBullet.TargetPositions.Dequeue(); if (clientBullet.CurrentPosition != null) { clientBullet.PassedPositions.Enqueue(clientBullet.CurrentPosition); } clientBullet.CurrentPosition = newCurrentPosition; clientBullet.IsReachedServerDeathPoint = clientBullet.CurrentPosition.IsFinishedPosition; } }
public void UpdateCall(ClientBulletMono clientBullet, float deltaTime) { //no need visual update if (clientBullet.CurrentPosition == null || clientBullet.TargetPositions.Count == 0 || clientBullet.IsDead) { return; } //on interpolation only start if (!clientBullet.IsLaunched) { clientBullet.IsLaunched = true; clientBullet.gameObject.SetActive(true); clientBullet.ObjectTransform.position = clientBullet.CurrentPosition.Position; return; } var targetInterpolationPoint = clientBullet.TargetPositions.First().Position; var currentInterpolationPoint = (Vector2)clientBullet.ObjectTransform.position; //check that we don't reach target var toTargetSqrDistance = (targetInterpolationPoint - currentInterpolationPoint).sqrMagnitude; var currentMovementMagnitude = clientBullet.ServerSpeed * deltaTime; if (toTargetSqrDistance < currentMovementMagnitude * currentMovementMagnitude) { //pop target as current location ExtractNewCurrentPosition(clientBullet); if (clientBullet.TargetPositions.Count == 0) { //if no other target put bullet on last known target clientBullet.ObjectTransform.position = targetInterpolationPoint; //if it was last traget kill client bullet if (clientBullet.IsReachedServerDeathPoint) { clientBullet.gameObject.SetActive(false); clientBullet.IsDead = true; } return; } //set new target targetInterpolationPoint = clientBullet.TargetPositions.First().Position; } //move bullet to target var movementVector = (targetInterpolationPoint - currentInterpolationPoint).normalized * currentMovementMagnitude; clientBullet.ObjectTransform.position = currentInterpolationPoint + movementVector; }
private void Extrapolate(ClientBulletMono clientBullet, float deltaTime) { var maxExtrapolation = clientBullet.ServerSpeed * TickDuration; var sqrMaxExtrapolation = maxExtrapolation * maxExtrapolation; var sqrDistanceFromCurrent = (clientBullet.CurrentPosition.Position - (Vector2)clientBullet.ObjectTransform.position).sqrMagnitude; if (sqrMaxExtrapolation <= sqrDistanceFromCurrent) { return; } var currentMovementVector = (Vector3)clientBullet.ServerVelocity.normalized * (clientBullet.ServerSpeed * deltaTime); clientBullet.ObjectTransform.position = clientBullet.ObjectTransform.position + currentMovementVector; }
public void UpdateCall(ClientBulletMono clientBullet, float deltaTime) { //no need visual update if bullet already or still dead if (!clientBullet.IsLaunched || clientBullet.IsDead) { return; } if (clientBullet.TargetPositions.Count >= 1) { Interpolate(clientBullet, deltaTime); } else { Extrapolate(clientBullet, deltaTime); } }
public void UpdateCall(ClientBulletMono clientBullet, float deltaTime) { if (clientBullet.CurrentPosition == null || clientBullet.IsDead) { return; } if (!clientBullet.IsLaunched) { clientBullet.IsLaunched = true; clientBullet.gameObject.SetActive(true); } clientBullet.ObjectTransform.position = clientBullet.CurrentPosition.Position; if (clientBullet.IsReachedServerDeathPoint) { clientBullet.gameObject.SetActive(false); clientBullet.IsDead = true; } }
public void ClientCall(ClientBulletMono clientBullet) { //waiting first point to interpolate if (clientBullet.CurrentPosition == null) { if (clientBullet.TargetPositions.Count < 1) { return; } ExtractNewCurrentPosition(clientBullet); //if we don't take several frame at once retern other go to logic of launch if (clientBullet.TargetPositions.Count == 0) { return; } } //waiting second point to interpolate or start extropolate if (!clientBullet.IsLaunched) { clientBullet.IsLaunched = true; clientBullet.ObjectTransform.position = clientBullet.CurrentPosition.Position; clientBullet.gameObject.SetActive(true); //if we don't take several frame at once retern other go to pop last data if (clientBullet.TargetPositions.Count > 1) { return; } } //pop all data to have one current point and one target while (clientBullet.TargetPositions.Count > 1) { ExtractNewCurrentPosition(clientBullet); } }