I would like to fix this problem I have with a grid based building system, basically the part where the the object is being spawned in front of the player and moves with the camera until it’s on its definitive location. BTW, it’s a 3rd person game.
This is the actual code I have, Gridsize is 300.f and tried several BuildDistance values, around 500.f being the point where I have the best results, but still far from smooth.
FVector UBuildManagerComponent::GetNextBuildLocation()
{
FVector DirectionVector = PlayerCamera->GetForwardVector() * BuildDistance;
DirectionVector += RpgCharacter->GetActorLocation();
return FVector(FMath::GridSnap(DirectionVector.X, GridSize), FMath::GridSnap(DirectionVector.Y, GridSize), FMath::GridSnap(DirectionVector.Z, GridSize));
}
It works decently when the object is at some exact location (in front of the player and not too close or too far), but I can’t move it from there without having to move the camera to a weird positions.
For instance, if I want to place an object 2 or 3 rows above the landscape the camera must be almost at floor level, and I can’t get any higher from there.
I think I need a more sophisticated algorithm but not sure where to start.
Any input would be really appreciated.