Coming from Unity over to Unreal and I am still catching my bearings.
I found LookAt very useful for pointing cameras and billboarding stuff. If there is anything similar and as easy to use I have not found it.
Any Ideas. Thanks in advance.
Coming from Unity over to Unreal and I am still catching my bearings.
I found LookAt very useful for pointing cameras and billboarding stuff. If there is anything similar and as easy to use I have not found it.
Any Ideas. Thanks in advance.
I don’t know about any functions included in Unreal, but I think it can be easily done as follows in your Character class:
// Look at Specific Actor
AYourCharacter::LookAt(AActor* actorToLookAt)
{
FVector viewDir = actorToLookAt->GetActorLocation() - this->GetPawnViewLocation();
(Cast<APlayerController>(Controller))->SetControlRotation(viewDir.Rotation());
}
I haven’t tried this yet, but I think it should work.
Yes this should work indeed thanks!
Sorry this is so late, but I just made a utility function within my custom UUtilities class I added to my project to do this. What’s different about it is that it takes a direction and an “up” vector, and produces the unique rotation as a quat. The problem with the solution discussed is that it produces a non-unique FRotator from a vector (imagine the line along the vector as an axle, and imagine your object rotating about it. All of those rotations are valid representations of that line).
FQuat UUtilities::CalculateLookAtRotation(const FVector& direction, const FVector& upVector)
{
return (FLookAtMatrix(FVector::ZeroVector, FVector::ForwardVector, FVector::UpVector) * FLookAtMatrix(FVector::ZeroVector, direction, upVector).Inverse()).ToQuat();
}
Best of luck.