message: Factored getDistance() method
diff: @@ -114,30 +114,8 @@ class Vehicle {
  rotation.Pitch = FMath::RadiansToDegrees(pose.rotation[1]);
  rotation.Yaw = FMath::RadiansToDegrees(pose.rotation[2]);
  - // See https://unrealcpp.com/line-trace-on-tick/
  -
  - // Start at a point at the bottom of the sphere enclosing the vehicle
  -
  - FVector startPoint = _pawn->GetActorLocation();
  - startPoint.Z -= _vehicleSize;
  -
  - // End at a point far below the sphere
  - FVector endPoint = FVector(startPoint.X, startPoint.Y, startPoint.Z-1e6);
  -
  - //DrawDebugLine(_pawn->GetWorld(), startPoint, endPoint, FColor::Green, false, 1, 0, 0.5);
  -
  - float agl = 0;
  -
  - // Trace a ray to the ground
  - FHitResult OutHit;
  - FCollisionQueryParams CollisionParams;
  - if (_pawn->GetWorld()->LineTraceSingleByChannel(OutHit, startPoint, endPoint, ECC_Visibility, CollisionParams)) {
  - if(OutHit.bBlockingHit) {
  - FVector impactPoint = OutHit.ImpactPoint;
  -
  - agl = (startPoint.Z - impactPoint.Z) / 100;
  - }
  - }
  + // Get AGL
  + float agl = getDistance();
  // Check for AGL going positive
  if (!_posagl) {
  @@ -154,6 +132,7 @@ class Vehicle {
  debugline("AGL = %3.2f m", agl);
  }
  + // Set vehicle pose in animation
  _pawn->SetActorLocation(location);
  _pawn->SetActorRotation(rotation);
  @@ -164,6 +143,32 @@ class Vehicle {
  // Animation effects (sound, spinning props)
  + // See https://unrealcpp.com/line-trace-on-tick/
  + float getDistance(void)
  + {
  + // Start at a point at the bottom of the sphere enclosing the vehicle
  +
  + FVector startPoint = _pawn->GetActorLocation();
  + startPoint.Z -= _vehicleSize;
  +
  + // End at a point far below the sphere
  + FVector endPoint = FVector(startPoint.X, startPoint.Y, startPoint.Z-1e6);
  +
  + //DrawDebugLine(_pawn->GetWorld(), startPoint, endPoint, FColor::Green, false, 1, 0, 0.5);
  +
  + // Trace a ray to any other mesh
  + FHitResult OutHit;
  + FCollisionQueryParams CollisionParams;
  + if (_pawn->GetWorld()->LineTraceSingleByChannel(OutHit, startPoint, endPoint, ECC_Visibility, CollisionParams)) {
  + if(OutHit.bBlockingHit) {
  + FVector impactPoint = OutHit.ImpactPoint;
  + return (startPoint.Z - impactPoint.Z) / 100;
  + }
  + }
  +
  + return 0;
  + }
  +
  void addAnimationEffects(void)
  {
  // Get motor values from dynamics
  