We are currently having a strange issue with our game when trying to make an actor look towards the player.
The player character can pickup packages or parcels using a Physics Handle once a package is held the position of this package can be moved around the player using the thumbstick on an Xbox controller. These steps all works fine.
We want to make it so the package is always looking towards the player and implemented it like so:
auto actorPos = GetActorLocation(); actorPos.Z = PhysicsHandle->TargetTransform.GetLocation().Z; auto rot = UKismetMathLibrary::FindLookAtRotation(actorPos, PhysicsHandle->TargetTransform.GetLocation()); rot.Yaw += 180; GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("Yaw %f"), rot.Yaw)); package->SetActorRotation(rot);
The reason Yaw is increased by 180 is because the FindLookAtRotation gives rotations in the following range: -180 to 180 which was not going to work due to at a certain point -180 would become 180
The problem we are having is when the package gets to a certain point it starts trying to spin around and have no idea why this would be happening.
I have made a video of it here: https://i.gyazo.com/fda08e427ca87e47a14f1fc9a76e632a.mp4
You can see the saw value on the screen and is being printed by the code seen above.
Does anybody know why the package starts to spin like this and know how to fix it?