void ABeaconLeagueGameMode::SpawnBeacon(const FVector &position)
{
	FVector respos = (position + FVector(0, 0, 20.0f));

	TArray<FOverlapResult> overlapResult;

	FCollisionQueryParams oParams(false);
	oParams.AddIgnoredActor(this);

	FCollisionResponseParams ResponseParam(ECollisionResponse::ECR_Block);

	World->OverlapMulti(overlapResult, respos, FQuat::Identity, ECollisionChannel::ECC_Pawn, FCollisionShape::MakeSphere(50), oParams);

	if (overlapResult.Num() > 1)
	{
		GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::Printf(TEXT("no puedes spawnear el beacon ahi! %d "), overlapResult.Num()));
	}
	else if (BeaconsSpawned.Num() == MAX_BEACONS)
	{
		BeaconsSpawned[NnewBeacon]->SetActorLocation(respos);
		NnewBeacon = (NnewBeacon + 1) % MAX_BEACONS;
	}
	else
	{
		AActor* newBeacon = World->SpawnActor(BeaconClass, &respos);

		if (newBeacon)
		{
			BeaconsSpawned.Add(newBeacon);
		}
		else
		{
			GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::Printf(TEXT("you cannot spawn a beacon there!")));
		}
	}
}
void AMobileEnemy::CheckCollision() {
  //Arrays RayCasting Results

  TArray<FHitResult> OutTraceResultMiddle;
  TArray<FHitResult> OutTraceResultTop;
  TArray<FHitResult> OutTraceResultBottom;

  //RayCasting StartPoint
  FVector StartTrace = m_lastPosition;
  FVector StartTraceTop = StartTrace + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding);
  FVector StartTraceBottom = StartTrace - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding);

  //Calculate de horizontal ray, to avoid "Y-AXIS Affect"
  FVector newLocationForward;
  newLocationForward.X = (FMath::Abs(GetActorRightVector().X) <= 0.01) ? m_lastPosition.X : m_nextPosition.X;
  newLocationForward.Y = (FMath::Abs(GetActorRightVector().Y) <= 0.01) ? m_lastPosition.Y : m_nextPosition.Y;
  newLocationForward.Z = (FMath::Abs(GetActorRightVector().Z) <= 0.01) ? m_lastPosition.Z : m_nextPosition.Z;

  //RayCasting EndPoint
  const FVector EndTraceMidle = newLocationForward + GetActorRightVector() * m_capsuleRadious;
  const FVector EndTraceTop = (newLocationForward + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding)) + GetActorRightVector() * m_capsuleRadious;
  const FVector EndTraceBottom = (newLocationForward - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding)) + GetActorRightVector() * m_capsuleRadious;

  // Setup the trace query  
  static FName FireTraceIdent = FName(TEXT("Platform"));
  FCollisionQueryParams TraceParams(FireTraceIdent, true, this);
  TraceParams.bTraceAsyncScene = true;
  TraceParams.bFindInitialOverlaps = true;
  TraceParams.bTraceComplex = true;

  FCollisionResponseParams ResponseParam(ECollisionResponse::ECR_Overlap);

  //FORWARD RAYCASTING
  GetWorld()->LineTraceMulti(OutTraceResultMiddle, StartTrace, EndTraceMidle, COLLISION_ENEMY, TraceParams, ResponseParam);
  bool collisionMidle = OutTraceResultMiddle.Num() > 0;
  //DrawDebugLine(GetWorld(), StartTraceTop, EndTraceTop, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
  GetWorld()->LineTraceMulti(OutTraceResultTop, StartTraceTop, EndTraceTop, COLLISION_ENEMY, TraceParams, ResponseParam);
  bool collisionTop = OutTraceResultTop.Num() > 0;

  GetWorld()->LineTraceMulti(OutTraceResultBottom, StartTraceBottom, EndTraceBottom, COLLISION_ENEMY, TraceParams, ResponseParam);
  bool collisionBottom = OutTraceResultBottom.Num() > 0;

  //check midle raycast
  if (collisionMidle) {
    int size = OutTraceResultMiddle.Num();
    for (int i = 0; i < size; i++)
      if (OutTraceResultMiddle[i].GetActor()->ActorHasTag("Platform")) {
      m_nextPosition = RecalculateLocation(GetActorRightVector(), m_nextPosition, OutTraceResultMiddle[i].Location, m_capsuleRadious);
      ResponseCollision();
      break;
      }
      else if (OutTraceResultMiddle[i].GetActor()->ActorHasTag("Player")) {
        if (m_tickCounter > 5) {
          ATowardsTheLightGameMode *gameMode = Cast<ATowardsTheLightGameMode>(UGameplayStatics::GetGameMode(this));
          if (gameMode)
            if (gameMode->EndGameBP() > -0.05)
              gameMode->EndGame(ATowardsTheLightGameMode::DEFEAT);

          if (!Fly)
            m_nextPosition = RecalculateLocation(GetActorRightVector(), m_nextPosition, OutTraceResultMiddle[i].Location, m_capsuleRadious);
          ResponseCollision();
          break;
        }

      }
  }
  //check top raycast
  if (collisionTop) {
    int size = OutTraceResultTop.Num();
    for (int i = 0; i < size; i++)
      if (OutTraceResultTop[i].GetActor()->ActorHasTag("Platform")) {
      m_nextPosition = RecalculateLocation(GetActorRightVector(), m_nextPosition, OutTraceResultTop[i].Location, m_capsuleRadious);
      ResponseCollision();
      break;
      }
      else if (OutTraceResultTop[i].GetActor()->ActorHasTag("Player")) {
        if (m_tickCounter > 5) {
          ATowardsTheLightGameMode *gameMode = Cast<ATowardsTheLightGameMode>(UGameplayStatics::GetGameMode(this));
          if (gameMode)
            if (gameMode->EndGameBP() > -0.05)
              gameMode->EndGame(ATowardsTheLightGameMode::DEFEAT);

          if (!Fly)
            m_nextPosition = RecalculateLocation(GetActorRightVector(), m_nextPosition, OutTraceResultTop[i].Location, m_capsuleRadious);
          ResponseCollision();
          break;
        }

      }
  }

  //check bottom raycast
  if (collisionBottom) {
    int size = OutTraceResultBottom.Num();
    for (int i = 0; i < size; i++)
      if (OutTraceResultBottom[i].GetActor()->ActorHasTag("Platform")) {
      m_nextPosition = RecalculateLocation(GetActorRightVector(), m_nextPosition, OutTraceResultBottom[i].Location, m_capsuleRadious);
      ResponseCollision();
      break;
      }
      else if (OutTraceResultBottom[i].GetActor()->ActorHasTag("Player")) {
        if (m_tickCounter > 5) {
          ATowardsTheLightGameMode *gameMode = Cast<ATowardsTheLightGameMode>(UGameplayStatics::GetGameMode(this));
          if (gameMode)
            if (gameMode->EndGameBP() > -0.05)
              gameMode->EndGame(ATowardsTheLightGameMode::DEFEAT);

          if (!Fly)
            m_nextPosition = RecalculateLocation(GetActorRightVector(), m_nextPosition, OutTraceResultBottom[i].Location, m_capsuleRadious);
          ResponseCollision();
          break;
        }

      }
  }

  //BACKWARD RAYCASTING
  TArray<FHitResult> OutTraceResultTopBack;
  TArray<FHitResult> OutTraceResultMiddleBack;
  TArray<FHitResult> OutTraceResultBottomBack;

  newLocationForward.X = (FMath::Abs(GetActorRightVector().X) <= 0.01) ? m_lastPosition.X : m_nextPosition.X;
  newLocationForward.Y = (FMath::Abs(GetActorRightVector().Y) <= 0.01) ? m_lastPosition.Y : m_nextPosition.Y;
  newLocationForward.Z = (FMath::Abs(GetActorRightVector().Z) <= 0.01) ? m_lastPosition.Z : m_nextPosition.Z;

  // Calculate the start location for trace back
  FVector StartTraceBack = newLocationForward;
  FVector StartTraceTopBack = StartTraceBack + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding);
  FVector StartTraceBottomBack = StartTraceBack - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding);

  const FVector EndTraceTopBack = (m_lastPosition + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding)) - GetActorRightVector() * (m_capsuleRadious - 5);
  const FVector EndTraceBottomBack = (m_lastPosition - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding)) - GetActorRightVector() * (m_capsuleRadious - 5);
  const FVector EndTraceMidleBack = m_lastPosition - GetActorRightVector() * (m_capsuleRadious - 5);

  GetWorld()->LineTraceMulti(OutTraceResultTopBack, StartTraceTopBack, EndTraceTopBack, COLLISION_ENEMY, TraceParams, ResponseParam);
  bool collisionTopBack = OutTraceResultTopBack.Num() > 0;

  GetWorld()->LineTraceMulti(OutTraceResultBottomBack, StartTraceBottomBack, EndTraceBottomBack, COLLISION_ENEMY, TraceParams, ResponseParam);
  bool collisionBottomBack = OutTraceResultBottomBack.Num() > 0;

  GetWorld()->LineTraceMulti(OutTraceResultMiddleBack, StartTraceBack, EndTraceMidleBack, COLLISION_ENEMY, TraceParams, ResponseParam);
  bool collisionMidleBack = OutTraceResultMiddleBack.Num() > 0;

  //check midle raycast
  if (collisionMidleBack) {
    int size = OutTraceResultMiddleBack.Num();
    for (int i = 0; i < size; i++)
      if (OutTraceResultMiddleBack[i].GetActor()->ActorHasTag("Platform")) {
      m_nextPosition = RecalculateLocation(-GetActorRightVector(), m_nextPosition, OutTraceResultMiddleBack[i].Location, m_capsuleRadious);
      ResponseCollision();
      break;
      }
      else if (OutTraceResultMiddleBack[i].GetActor()->ActorHasTag("Player")) {
        if (m_tickCounter > 5) {
          ATowardsTheLightGameMode *gameMode = Cast<ATowardsTheLightGameMode>(UGameplayStatics::GetGameMode(this));
          if (gameMode)
            if (gameMode->EndGameBP() > -0.05)
              gameMode->EndGame(ATowardsTheLightGameMode::DEFEAT);

          if (!Fly)
            m_nextPosition = RecalculateLocation(-GetActorRightVector(), m_nextPosition, OutTraceResultMiddleBack[i].Location, m_capsuleRadious);
          ResponseCollision();
          break;
        }

      }
  }
  //check top raycast
  if (collisionTopBack) {
    int size = OutTraceResultTopBack.Num();
    for (int i = 0; i < size; i++)
      if (OutTraceResultTopBack[i].GetActor()->ActorHasTag("Platform")) {
      m_nextPosition = RecalculateLocation(-GetActorRightVector(), m_nextPosition, OutTraceResultTopBack[i].Location, m_capsuleRadious);
      ResponseCollision();
      break;
      }
      else if (OutTraceResultTopBack[i].GetActor()->ActorHasTag("Player")) {
        if (m_tickCounter > 5) {
          ATowardsTheLightGameMode *gameMode = Cast<ATowardsTheLightGameMode>(UGameplayStatics::GetGameMode(this));
          if (gameMode)
            if (gameMode->EndGameBP() > -0.05)
              gameMode->EndGame(ATowardsTheLightGameMode::DEFEAT);

          if (!Fly)
            m_nextPosition = RecalculateLocation(-GetActorRightVector(), m_nextPosition, OutTraceResultTopBack[i].Location, m_capsuleRadious);
          ResponseCollision();
          break;
        }

      }
  }

  //check bottom raycast
  if (collisionBottomBack) {
    int size = OutTraceResultBottomBack.Num();
    for (int i = 0; i < size; i++)
      if (OutTraceResultBottomBack[i].GetActor()->ActorHasTag("Platform")) {
      m_nextPosition = RecalculateLocation(-GetActorRightVector(), m_nextPosition, OutTraceResultBottomBack[i].Location, m_capsuleRadious);
      ResponseCollision();
      break;
      }
      else if (OutTraceResultBottomBack[i].GetActor()->ActorHasTag("Player")) {
        if (m_tickCounter > 5) {
          ATowardsTheLightGameMode *gameMode = Cast<ATowardsTheLightGameMode>(UGameplayStatics::GetGameMode(this));
          if (gameMode)
            if (gameMode->EndGameBP() > -0.05)
              gameMode->EndGame(ATowardsTheLightGameMode::DEFEAT);

          if (!Fly)
            m_nextPosition = RecalculateLocation(-GetActorRightVector(), m_nextPosition, OutTraceResultBottomBack[i].Location, m_capsuleRadious);
          ResponseCollision();
          break;
        }

      }
  }


  if (!Fly) {
    TArray<FHitResult> OutTraceResultDown;
    TArray<FHitResult> OutTraceResultDownLeftF;
    TArray<FHitResult> OutTraceResultDownRigthF;

    FVector StartTraceLeftF = StartTrace + GetActorRightVector() * (m_capsuleRadious - m_capsuleRadiousPadding);
    FVector StartTraceRigthF = StartTrace - GetActorRightVector() * (m_capsuleRadious - m_capsuleRadiousPadding);

    FVector newLocationUp;
    newLocationUp.X = (FMath::Abs(GetActorUpVector().X) <= 0.01) ? m_lastPosition.X : m_nextPosition.X;
    newLocationUp.Y = (FMath::Abs(GetActorUpVector().Y) <= 0.01) ? m_lastPosition.Y : m_nextPosition.Y;
    newLocationUp.Z = (FMath::Abs(GetActorUpVector().Z) <= 0.01) ? m_lastPosition.Z : m_nextPosition.Z;

    const FVector EndTraceDown = newLocationUp - GetActorUpVector() * m_capsuleHeight;
    const FVector EndTraceDownLeftF = (newLocationUp + GetActorRightVector() * (m_capsuleRadious - m_capsuleRadiousPadding)) - GetActorUpVector() * m_capsuleHeight;
    const FVector EndTraceDownRightF = (newLocationUp - GetActorRightVector() * (m_capsuleRadious - m_capsuleRadiousPadding)) - GetActorUpVector() * m_capsuleHeight;

    GetWorld()->LineTraceMulti(OutTraceResultDownLeftF, StartTraceLeftF, EndTraceDownLeftF, COLLISION_ENEMY, TraceParams, ResponseParam);
    bool collisionDownLeftF = OutTraceResultDownLeftF.Num() > 0;

    GetWorld()->LineTraceMulti(OutTraceResultDownRigthF, StartTraceRigthF, EndTraceDownRightF, COLLISION_ENEMY, TraceParams, ResponseParam);
    bool collisionDownRightF = OutTraceResultDownRigthF.Num() > 0;

    GetWorld()->LineTraceMulti(OutTraceResultDown, StartTrace, EndTraceDown, COLLISION_ENEMY, TraceParams, ResponseParam);
    bool collisionDown = OutTraceResultDown.Num() > 0;

    bool eGravity = true;
    if (collisionDown || collisionDownLeftF || collisionDownRightF) {
      if (collisionDown) {
        int size = OutTraceResultDown.Num();
        for (int i = 0; i < size; i++)
          if (OutTraceResultDown[i].GetActor()->ActorHasTag("Platform")) {
          m_nextPosition = RecalculateLocation(GetActorUpVector(), m_nextPosition, OutTraceResultDown[i].Location, -m_capsuleHeight);
          m_enableGravity = false;
          eGravity = false;
          m_actualJumpSpeed = 0;
          break;
          }
      }
      else if (collisionDownLeftF) {
        int size = OutTraceResultDownLeftF.Num();
        for (int i = 0; i < size; i++)
          if (OutTraceResultDownLeftF[i].GetActor()->ActorHasTag("Platform")) {
          m_nextPosition = RecalculateLocation(GetActorUpVector(), m_nextPosition, OutTraceResultDownLeftF[i].Location, -m_capsuleHeight);
          m_enableGravity = false;
          eGravity = false;
          m_actualJumpSpeed = 0;
          break;
          }
      }
      else if (collisionDownRightF) {
        int size = OutTraceResultDownRigthF.Num();
        for (int i = 0; i < size; i++)
          if (OutTraceResultDownRigthF[i].GetActor()->ActorHasTag("Platform")) {
          m_nextPosition = RecalculateLocation(GetActorUpVector(), m_nextPosition, OutTraceResultDownRigthF[i].Location, -m_capsuleHeight);
          m_enableGravity = false;
          eGravity = false;
          m_actualJumpSpeed = 0;
          break;
          }
      }
      else {
        m_enableGravity = true;
      }

      if (eGravity)
        m_enableGravity = true;

    }
    else {
      m_enableGravity = true;
    }
  }
}
示例#3
0
void APlayerOvi::CheckCollision() {


  TArray<FHitResult> OutTraceResultTop;
  TArray<FHitResult> OutTraceResultBody;
  TArray<FHitResult> OutTraceResultMiddle;
  TArray<FHitResult> OutTraceResultLegs;
  TArray<FHitResult> OutTraceResultBottom;

  // Calculate the start location for trace  
  FVector StartTrace = m_lastPosition;
  FVector StartTraceTop = StartTrace + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding);
  FVector StartTraceBottom = StartTrace - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding);

  FVector StartTraceBody = StartTrace + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPaddingFeet);
  FVector StartTraceLegs = StartTrace - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPaddingFeet);

  FVector StartTraceLeftF = StartTrace + GetActorForwardVector() * (m_capsuleRadious - m_capsuleRadiousPadding);
  FVector StartTraceRigthF = StartTrace - GetActorForwardVector() * (m_capsuleRadious - m_capsuleRadiousPadding);

  // Calculate the end location for trace  
  //horizontal
  FVector newLocationForward;
  newLocationForward.X = (FMath::Abs(GetActorForwardVector().X) <= 0.01) ? m_lastPosition.X : GetActorLocation().X;
  newLocationForward.Y = (FMath::Abs(GetActorForwardVector().Y) <= 0.01) ? m_lastPosition.Y : GetActorLocation().Y;
  newLocationForward.Z = (FMath::Abs(GetActorForwardVector().Z) <= 0.01) ? m_lastPosition.Z : GetActorLocation().Z;

  const FVector EndTraceTop = (newLocationForward + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding)) + GetActorForwardVector() * m_capsuleRadious;
  const FVector EndTraceBottom = (newLocationForward - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding)) + GetActorForwardVector() * m_capsuleRadious;
  const FVector EndTraceBody = (newLocationForward + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPaddingFeet)) + GetActorForwardVector() * m_capsuleRadious;
  const FVector EndTraceLegs = (newLocationForward - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPaddingFeet)) + GetActorForwardVector() * m_capsuleRadious;
  const FVector EndTraceMidle = newLocationForward + GetActorForwardVector() * m_capsuleRadious;
 
  FCollisionResponseParams ResponseParam(ECollisionResponse::ECR_Overlap);

  GetWorld()->LineTraceMulti(OutTraceResultTop, StartTraceTop, EndTraceTop, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  bool collisionTop = OutTraceResultTop.Num() > 0;
  //DrawDebugLine(GetWorld(), StartTraceTop, EndTraceTop, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
  GetWorld()->LineTraceMulti(OutTraceResultBottom, StartTraceBottom, EndTraceBottom, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  bool collisionBottom = OutTraceResultBottom.Num() > 0;
  //DrawDebugLine(GetWorld(), StartTraceBottom, EndTraceBottom, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
  GetWorld()->LineTraceMulti(OutTraceResultBody, StartTraceBody, EndTraceBody, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  bool collisionBody = OutTraceResultBody.Num() > 0;
  //DrawDebugLine(GetWorld(), StartTraceBody, EndTraceBody, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
  GetWorld()->LineTraceMulti(OutTraceResultLegs, StartTraceLegs, EndTraceLegs, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  bool collisionLegs = OutTraceResultLegs.Num() > 0;
  //DrawDebugLine(GetWorld(), StartTraceLegs, EndTraceLegs, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);

  GetWorld()->LineTraceMulti(OutTraceResultMiddle, StartTrace, EndTraceMidle, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  bool collisionMidle = OutTraceResultMiddle.Num() > 0;
  //DrawDebugLine(GetWorld(), StartTrace, EndTraceMidle, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);

  if (collisionTop || collisionBottom || collisionMidle) {

    if (collisionMidle) {
      int size = OutTraceResultMiddle.Num();
      for (int i = 0; i < size; i++)
        if (OutTraceResultMiddle[i].GetActor()->ActorHasTag("Platform")) {
        SetActorLocation(RecalculateLocation(GetActorForwardVector(), GetActorLocation(), OutTraceResultMiddle[i].Location, m_capsuleRadious));
        break;
        }
    }
    if (collisionTop) {
      int size = OutTraceResultTop.Num();
      for (int i = 0; i < size; i++)
        if (OutTraceResultTop[i].GetActor()->ActorHasTag("Platform")) {
        SetActorLocation(RecalculateLocation(GetActorForwardVector(), GetActorLocation(), OutTraceResultTop[i].Location, m_capsuleRadious));
        break;
        }
    }
    if (collisionBottom) {
      int size = OutTraceResultBottom.Num();
      for (int i = 0; i < size; i++)
        if (OutTraceResultBottom[i].GetActor()->ActorHasTag("Platform")) {
        SetActorLocation(RecalculateLocation(GetActorForwardVector(), GetActorLocation(), OutTraceResultBottom[i].Location, m_capsuleRadious));
        break;
        }
    }
  }
  else {
    TArray<FHitResult> OutTraceResultTopBack;
    TArray<FHitResult> OutTraceResultBodyBack;
    TArray<FHitResult> OutTraceResultMiddleBack;
    TArray<FHitResult> OutTraceResultBottomBack;
    TArray<FHitResult> OutTraceResultLegsBack;

    // Calculate the start location for trace back
    FVector StartTraceBack = newLocationForward;
    FVector StartTraceTopBack = StartTraceBack + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding);
    FVector StartTraceBottomBack = StartTraceBack - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding);

    FVector StartTraceBodyBack = StartTraceBack + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPaddingFeet);
    FVector StartTraceLegsBack = StartTraceBack - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPaddingFeet);

    //cambiado a last_position porque va hacia atras y la posicion nueva siempre sera hacia adelante.
    const FVector EndTraceTopBack = (m_lastPosition + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding)) - GetActorForwardVector() * m_capsuleRadious;
    const FVector EndTraceBottomBack = (m_lastPosition - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPadding)) - GetActorForwardVector() * m_capsuleRadious;
    const FVector EndTraceBodyBack = (m_lastPosition + GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPaddingFeet)) - GetActorForwardVector() * m_capsuleRadious;
    const FVector EndTraceLegsBack = (m_lastPosition - GetActorUpVector() * (m_capsuleHeight - m_capsuleHeightPaddingFeet)) - GetActorForwardVector() * m_capsuleRadious;
    const FVector EndTraceMidleBack = m_lastPosition - GetActorForwardVector() * m_capsuleRadious;

    GetWorld()->LineTraceMulti(OutTraceResultTopBack, StartTraceTopBack, EndTraceTopBack, COLLISION_PLAYER, m_TraceParams, ResponseParam);
    bool collisionTopBack = OutTraceResultTopBack.Num() > 0;
    //DrawDebugLine(GetWorld(), StartTraceTopBack, EndTraceTopBack, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
    GetWorld()->LineTraceMulti(OutTraceResultBottomBack, StartTraceBottomBack, EndTraceBottomBack, COLLISION_PLAYER, m_TraceParams, ResponseParam);
    bool collisionBottomBack = OutTraceResultBottomBack.Num() > 0;
    //DrawDebugLine(GetWorld(), StartTraceBottomBack, EndTraceBottomBack, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);

    GetWorld()->LineTraceMulti(OutTraceResultBodyBack, StartTraceBodyBack, EndTraceBodyBack, COLLISION_PLAYER, m_TraceParams, ResponseParam);
    bool collisionBodyBack = OutTraceResultBodyBack.Num() > 0;
    //DrawDebugLine(GetWorld(), StartTraceBodyBack, EndTraceBodyBack, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
    GetWorld()->LineTraceMulti(OutTraceResultLegsBack, StartTraceLegsBack, EndTraceLegsBack, COLLISION_PLAYER, m_TraceParams, ResponseParam);
    bool collisionLegsBack = OutTraceResultLegsBack.Num() > 0;
    //DrawDebugLine(GetWorld(), StartTraceLegsBack, EndTraceLegsBack, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);

    GetWorld()->LineTraceMulti(OutTraceResultMiddleBack, StartTraceBack, EndTraceMidleBack, COLLISION_PLAYER, m_TraceParams, ResponseParam);
    bool collisionMidleBack = OutTraceResultMiddleBack.Num() > 0;

    //DrawDebugLine(GetWorld(), StartTraceBack, EndTraceMidleBack, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
    if (collisionTopBack || collisionBottomBack || collisionMidleBack) {
      if (collisionMidleBack) {
        int size = OutTraceResultMiddleBack.Num();
        for (int i = 0; i < size; i++)
          if (OutTraceResultMiddleBack[i].GetActor()->ActorHasTag("MobilePlatform")) {
          if (!isPlayerRunning())
            SetActorLocation(RecalculateLocation(-GetActorForwardVector(), GetActorLocation(), OutTraceResultMiddleBack[i].Location, m_capsuleRadious));
          break;
          }
      }
      if (collisionTopBack) {
        if (collisionBodyBack) {
          int size = OutTraceResultTopBack.Num();
          for (int i = 0; i < size; i++)
            if (OutTraceResultTopBack[i].GetActor()->ActorHasTag("MobilePlatform")) {
            if (!isPlayerRunning())
              SetActorLocation(RecalculateLocation(-GetActorForwardVector(), GetActorLocation(), OutTraceResultTopBack[i].Location, m_capsuleRadious));
            break;
            }
        }
      }
      if (collisionBottomBack) {
        if (collisionLegsBack) {
          int size = OutTraceResultBottomBack.Num();
          for (int i = 0; i < size; i++)
            if (OutTraceResultBottomBack[i].GetActor()->ActorHasTag("MobilePlatform")) {
            if (!isPlayerRunning())
              SetActorLocation(RecalculateLocation(-GetActorForwardVector(), GetActorLocation(), OutTraceResultBottomBack[i].Location, m_capsuleRadious));
            break;
            }
        }
      }
    }
  }
  // Calculate the end location for trace  
  // Vertical 
  TArray<FHitResult> OutTraceResultDown;
  TArray<FHitResult> OutTraceResultDownLeftF;
  TArray<FHitResult> OutTraceResultDownRigthF;

  TArray<FHitResult> OutTraceResultUp;
  TArray<FHitResult> OutTraceResultUpLeftF;
  TArray<FHitResult> OutTraceResultUpRigthF;

  FVector newLocationUp;
  newLocationUp.X = (FMath::Abs(GetActorUpVector().X) <= 0.01) ? m_lastPosition.X : GetActorLocation().X;
  newLocationUp.Y = (FMath::Abs(GetActorUpVector().Y) <= 0.01) ? m_lastPosition.Y : GetActorLocation().Y;
  newLocationUp.Z = (FMath::Abs(GetActorUpVector().Z) <= 0.01) ? m_lastPosition.Z : GetActorLocation().Z;
  bool action = false;


  const FVector EndTraceDownLeftF = (newLocationUp + GetActorForwardVector() * (m_capsuleRadious - m_capsuleRadiousPadding)) - GetActorUpVector() * m_capsuleHeight;
  GetWorld()->LineTraceMulti(OutTraceResultDownLeftF, StartTraceLeftF, EndTraceDownLeftF, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  bool collisionDownLeftF = OutTraceResultDownLeftF.Num() > 0;

  if (collisionDownLeftF) {
    if (collisionBottom == collisionLegs) {
      int size = OutTraceResultDownLeftF.Num();
      for (int i = 0; i < size; i++)
        if (OutTraceResultDownLeftF[i].GetActor()->ActorHasTag("Platform")) {
          if (OutTraceResultDownLeftF[i].GetActor()->ActorHasTag("MobilePlatform")) {
            AMobilePlatform *movil = dynamic_cast<AMobilePlatform *>(OutTraceResultDownLeftF[i].GetActor());
            if (movil) {
              if (m_currentMobile)
                if (m_currentMobile != movil)
                  m_currentMobile->SetPlayerOn(false);
              m_currentMobile = movil;
              m_currentMobile->SetPlayerOn(true);
            }
          }
          else {
            if (m_currentMobile) {
              m_currentMobile->SetPlayerOn(false);
              m_isOnMobilePlatform = false;
              m_currentMobile = nullptr;
            }
          }
        FVector localizaion = OutTraceResultDownLeftF[i].Location;
        action = true;
        SetActorLocation(RecalculateLocation(GetActorUpVector(), GetActorLocation(), OutTraceResultDownLeftF[i].Location, -m_capsuleHeight));
        m_hasLanded = true;
        m_isFalling = false;
        m_actualJumpSpeed = JumpSpeed;
        break;
        }
    }
  }
  newLocationUp.X = (FMath::Abs(GetActorUpVector().X) <= 0.01) ? m_lastPosition.X : GetActorLocation().X;
  newLocationUp.Y = (FMath::Abs(GetActorUpVector().Y) <= 0.01) ? m_lastPosition.Y : GetActorLocation().Y;
  newLocationUp.Z = (FMath::Abs(GetActorUpVector().Z) <= 0.01) ? m_lastPosition.Z : GetActorLocation().Z;
  const FVector EndTraceDownRightF = (newLocationUp - GetActorForwardVector() * (m_capsuleRadious - m_capsuleRadiousPadding)) - GetActorUpVector() * m_capsuleHeight;
  GetWorld()->LineTraceMulti(OutTraceResultDownRigthF, StartTraceRigthF, EndTraceDownRightF, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  bool collisionDownRightF = OutTraceResultDownRigthF.Num() > 0;

  if (collisionDownRightF) {
    int size = OutTraceResultDownRigthF.Num();
    for (int i = 0; i < size; i++)
      if (OutTraceResultDownRigthF[i].GetActor()->ActorHasTag("Platform")) {
      if (OutTraceResultDownRigthF[i].GetActor()->ActorHasTag("MobilePlatform")) {
        AMobilePlatform *movil = dynamic_cast<AMobilePlatform *>(OutTraceResultDownRigthF[i].GetActor());
        if (movil) {
          if (m_currentMobile)
            if (m_currentMobile != movil)
              m_currentMobile->SetPlayerOn(false);
          m_currentMobile = movil;
          m_currentMobile->SetPlayerOn(true);
        }
      }
      else {
        if (m_currentMobile) {
          m_currentMobile->SetPlayerOn(false);
          m_isOnMobilePlatform = false;
          m_currentMobile = nullptr;
        }
      }
      action = true;
      FVector localizaion = OutTraceResultDownRigthF[i].Location;
      SetActorLocation(RecalculateLocation(GetActorUpVector(), GetActorLocation(), OutTraceResultDownRigthF[i].Location, -m_capsuleHeight));
      m_hasLanded = true;
      m_isFalling = false;
      m_actualJumpSpeed = JumpSpeed;
      break;
      }
  }

  if (!action)
  {
    if (m_currentMobile) {
      m_currentMobile->SetPlayerOn(false);
      m_isOnMobilePlatform = false;
      m_currentMobile = nullptr;
    }
    m_hasLanded = false;
  }

  newLocationUp.X = (FMath::Abs(GetActorUpVector().X) <= 0.01) ? m_lastPosition.X : GetActorLocation().X;
  newLocationUp.Y = (FMath::Abs(GetActorUpVector().Y) <= 0.01) ? m_lastPosition.Y : GetActorLocation().Y;
  newLocationUp.Z = (FMath::Abs(GetActorUpVector().Z) <= 0.01) ? m_lastPosition.Z : GetActorLocation().Z;

  //const FVector EndTraceUp = newLocationUp + GetActorUpVector() * m_capsuleHeight;
  const FVector EndTraceUpLeftF = (newLocationUp + GetActorForwardVector() * (m_capsuleRadious - m_capsuleRadiousPadding)) + GetActorUpVector() * m_capsuleHeight;
  const FVector EndTraceUpRightF = (newLocationUp - GetActorForwardVector() * (m_capsuleRadious - m_capsuleRadiousPadding)) + GetActorUpVector() * m_capsuleHeight;

  //GetWorld()->LineTraceMulti(OutTraceResultUp, StartTrace, EndTraceUp, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  //DrawDebugLine(GetWorld(), StartTrace, EndTraceUp, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
  //bool collisionUp = OutTraceResultUp.Num() > 0;
  
  GetWorld()->LineTraceMulti(OutTraceResultUpLeftF, StartTraceLeftF, EndTraceUpLeftF, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  //DrawDebugLine(GetWorld(), StartTraceLeftF, EndTraceUpLeftF, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
  bool collisionUpLeftF = OutTraceResultUpLeftF.Num() > 0;
  GetWorld()->LineTraceMulti(OutTraceResultUpRigthF, StartTraceRigthF, EndTraceUpRightF, COLLISION_PLAYER, m_TraceParams, ResponseParam);
  //DrawDebugLine(GetWorld(), StartTraceRigthF, EndTraceUpRightF, FColor(1.0f, 0.f, 0.f, 1.f), false, 10.f);
  bool collisionUpRightF = OutTraceResultUpRigthF.Num() > 0;

  if (collisionUpLeftF) {
      int size = OutTraceResultUpLeftF.Num();
      for (int i = 0; i < size; i++)
        if (OutTraceResultUpLeftF[i].GetActor()->ActorHasTag("Platform")) {
          if (OutTraceResultUpLeftF[i].GetActor()->ActorHasTag("MobilePlatform"))
            SetActorLocation(RecalculateLocation(GetActorUpVector(), GetActorLocation(), OutTraceResultUpLeftF[i].Location, m_capsuleHeight + 20));
          else
            SetActorLocation(RecalculateLocation(GetActorUpVector(), GetActorLocation(), OutTraceResultUpLeftF[i].Location, m_capsuleHeight));

          m_headCollision = true;
          m_actualJumpSpeed = 0.0f;
          break;
        }
  }
  else if (collisionUpRightF) {
    int size = OutTraceResultUpRigthF.Num();
    for (int i = 0; i < size; i++)
      if (OutTraceResultUpRigthF[i].GetActor()->ActorHasTag("Platform")) {
        if (OutTraceResultUpRigthF[i].GetActor()->ActorHasTag("MobilePlatform"))
          SetActorLocation(RecalculateLocation(GetActorUpVector(), GetActorLocation(), OutTraceResultUpRigthF[i].Location, m_capsuleHeight + 20));
        else
          SetActorLocation(RecalculateLocation(GetActorUpVector(), GetActorLocation(), OutTraceResultUpRigthF[i].Location, m_capsuleHeight));

        m_headCollision = true;
        m_actualJumpSpeed = 0.0f;
        break;
      }
  }
  
}