Announcement

Collapse
No announcement yet.

Character rotation on Z direction

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Character rotation on Z direction

    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 :
    Code:
    void AMyProjectCharacter::TurnYaw(float Rate)
    {
    	AddControllerYawInput(Rate);
    	AddActorLocalRotation(FRotator(0, FirstPersonCameraComponent->RelativeRotation.Yaw, 0));
    }
    - And in the tick event of the Sphere class :
    Code:
    // 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 :
    Click image for larger version

Name:	MyProjectPicture01.png
Views:	1
Size:	558.1 KB
ID:	1143937

    We can see the mesh is correctly directed, with mouse position.

    And if I turn the mouse 180° :
    Click image for larger version

Name:	MyProjectPicture02.png
Views:	1
Size:	521.3 KB
ID:	1143938
    (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
Working...
X