# Unity – rotation problem in Mario galaxy like controller

I make a Mario galaxy like CCC.
And I have a serious rotation problem, maybe Gimble-Lock or not.

First, I have a parent object ("PLAYER") who can turn in the direction of a planet:
https://youtu.be/j3VkemYQTa8

With this 3 line:

``````Vector3 dirOrientation = GetNormal () // Here is the normal collision
Quaternion targetRotation = Quaternion.FromToRotation (PLAYER.transform.up, dirOrientation) * PLAYER.transform.rotation;
PLAYER.transform.rotation = Quaternion.RotateTowards (PLAYER.transform.rotation, targetRotation, speedRotate);
``````

Ok, next I want to rotate the child object ("CHILDREN PLAYER") containing the render, according to the input of the player
See the editor:
https://youtu.be/4Sb8t82OT-E

So here … I have determined the direction of the input after the camera.
See the direction line in blue: The Vector3 point points in the direction of the player and the camera in the right direction, yes!
https://youtu.be/4TvPsXp-W9U

``````Vector2 dirInput = playerInput.GetDirInput (); // input player with the stick, X, Y
// Here is REFOBJECT the camera (which dictates the "forward" of the player
Vector3 relativeDirection = REFOBJECT.right * dirInput.x + REFOBJECT .forward * dirInput.y;
Debug.DrawRay (CHILDPLAYER.position, relativeDirection, Color.cyan, 0.4f);
``````

But now … As you can see, even if I have the good direction (see blue line in the video). I can not manage to rotate the child gameObject accordingly … I have to do that locally locally CHILDREN PLAYER only in Y to my newly calculated vector …

Here's the code I use to turn it CHILDREN PLAYER, With my relative direction vector3:

``````CHILDPLAYER.localRotation = DirObject (CHILDPLAYER.localRotation, relativeDirection, TurnRate);

public Quaternion DirObject (Quaternion rotation, Vector3 direction, Float TurnRate)
{
Float header = Mathf.Atan2 (-dir.x * turnRate * Time.deltaTime, dir.z * turnRate * Time.deltaTime);

Quaternion _targetRotation = Quaternion.identity;

Float x = 0;
float y = Heading * -1 * Mathf.Rad2Deg;
float z = 0;

_targetRotation = Quaternion.Euler (x, y, z);
Rotation = Quaternion.RotateTowards (rotation, _targetRotation, turnRate * Time.deltaTime);
Return (rotation);
}
``````

See the final result:

Here I ALWAYS go down with the stick … and even if the direction computed in relativeDirection is good, the children's game turn themselves … …