Hi folks!
I’m having some trouble getting my spawned actor to align to another actor’s normal correctly. I’m using a snapping system so it aligns 200x200, without the snap system the alignment is fine, but I really want this snap system .
Most of the time it aligns perfect on flat surfaces but when it comes to rotated actors at for example 45 degrees then it has trouble aligning correctly.
Here is an image of the alignment working correctly on flat surfaces:
Here is an image of what is happening on rotated actor’s:
There is another small issue I’m having that happens on some surfaces, not sure why as the actors on these following images are the same but just placed next to eachother:
Here is another image of the alignment working correctly:
And not working correctly:
As far as I can tell the Normals of each actor are exactly the same. so I’m not entirely sure what the issue is on that last one but any help would be much appreciated!
Here’s my code:
void AQUBECharacterPlayer::CharacterTrace(FVector& CameraLocation, FRotator& CameraRotation, FHitResult& HitResult)
{
if(Controller)
{
Controller->GetPlayerViewPoint(CameraLocation, CameraRotation);
FCollisionQueryParams CollisionQuery(NAME_None, false, this);
if (GetWorld()->LineTraceSingle(HitResult, CameraLocation, CameraLocation + CameraRotation.Vector() * 10000, ECC_WorldStatic, CollisionQuery))
{
if(HitResult.GetActor())
{
if(HitResult.GetActor()->HasTag(TEXT("Interact")) || HitResult.GetActor()->HasTag(TEXT("PhysicsActor")) || HitResult.GetActor()->HasTag(TEXT("CanMove")))
{
return;
}
BuildLocation = HitResult.ImpactPoint;
BuildLocation.X = BuildLocation.X + 200.0 / 2.0 * HitResult.ImpactNormal.X;
BuildLocation.X = FMath::Round(BuildLocation.X / 200.0) * 200.0;
BuildLocation.Y = BuildLocation.Y + 200.0 / 2.0 * HitResult.ImpactNormal.Y;
BuildLocation.Y = FMath::Round(BuildLocation.Y / 200.0) * 200.0;
BuildLocation.Z = BuildLocation.Z + 200.0 / 2.0 * HitResult.ImpactNormal.Z;
BuildLocation.Z = FMath::Round(BuildLocation.Z / 200.0) * 200.0;
}
}
}
}
In Tick:
FVector CamLoc;
FRotator CamRot;
FHitResult HitResult;
/*
* Start of ***BLUE*** cube mini spawnable code
*/
if(bPreThrowBlue)
{
CharacterTrace(CamLoc, CamRot, HitResult);
if(HitResult.GetActor() == SpawnedRedCube || HitResult.GetActor() == SpawnedGreenCube)
{
return;
}
if(SpawnedBlueCubeGhost)
{
SpawnedBlueCubeGhost->SetActorLocation(BuildLocation);
SpawnedBlueCubeGhost->SetActorRotation(HitResult.ImpactNormal.Rotation() + FRotator(-90,0,0));
}
}
/*
* End of BLUE cube mini spawnable code
*/
...
...
THANKS!!