I’m trying to solve that. (i’m getting some random directions D:)
UWorld* World = GetWorld();
FVector2D Viewport;
World->GetGameViewport()->GetViewportSize(Viewport);
FVector WorldPosition;
FVector WorldDirection;
const FVector StartTrace = CurrentWeapon->WeaponMesh->GetSocketLocation("MF");
AMyPlayerController* MyPC = Cast<AMyPlayerController>(Controller);
if( MyPC->DeprojectScreenPositionToWorld((Viewport.X), (Viewport.Y), WorldPosition, WorldDirection))
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Blue, TEXT("Deprojected!"));
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
FVector Destination = (WorldPosition + WorldDirection) * CurrentWeapon->WeaponConfig.WeaponRange;
FHitResult Hit = WeaponTrace(WorldPosition, Destination);
FVector RotNorm = (Destination - StartTrace);
if(RotNorm.Normalize())
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Purple, TEXT("Normalized!"));
FRotator Rot = RotNorm.Rotation();
AWeaponBullet* Projectile = World->SpawnActor<AWeaponBullet>(ProjectileClass, StartTrace , Rot, SpawnParams);
i’m doing something wrong? (I have some debug things, like lines. I have removed from this anwser)
PS:
Range = 3000.0f;
“MF” = “Muzzle Flash”
PS2: AHUD Is not working (is not updating my Position and Direction), i did all right, getting and casting my HUD (and I checked if I succeeded on cast), so, Controller is working well.
(I also tried divide by 2 the X an Y viewport) and this Hit.Location()