Hello,
I search a way to rotate a character after his Z axis is direct to an an actor (here a sphere).
For the moment I have this :
-
I uncheck the option “Use controller rotation Yaw”.
-
Into my Character class a add this code for rotate it by the mouse event :
void AMyProjectCharacter::TurnYaw(float Rate)
{
AddControllerYawInput(Rate);
AddActorLocalRotation(FRotator(0, FirstPersonCameraComponent->RelativeRotation.Yaw, 0));
}
- And in the tick event of the Sphere class :
// Calculate the direction of the sphere
FRotator DirectionRotation = (GetActorLocation() - character->GetActorLocation()).Rotation();
// 90 it's for the feet are moving towards the sphere (with it or not, the problem is the same).
DirectionRotation.Pitch += 90;
// Set new direction to character
character->SetActorRotation(DirectionRotation);
The result :
We can see the mesh is correctly directed, with mouse position.
And if I turn the mouse 180° :
(I take two shot and mix their to have the same effect as the display)
The mesh have a different rotation for each frame and the character rotation is not at -180 like the mouse (without code into sphere class, the Yaw correctly work).
Have you an example, or a way for resolve it ?
Thanks in advance.
Dams