Rotation Issue

Hie everyone I want to rotate my character like in this video

Here is the link

RotationValues= new vector3(0,95,0);

void Rotate()

    {
   
        quaternionA = Player.transform.rotation;
     
      Player.transform.rotation=  Quaternion.Slerp(quaternionA, Quaternion.Euler(RotationValues), Rotatingvalue);
     
      Rotatingvalue += Time.deltaTime;

    
  
     
    }

Please help me ,
Thanks for in advance

This doesn’t seem to be physics-related, just some basic transform rotation. And if you want to do the same thing you see here, turning only 90 degrees left or right, I’d say a simple Coroutine using euler angles would be fine. It seems the camera is a child of the player, so rotating the player alone should be fine. Something like this. I haven’t testing this, but I imagine it’s probably a reasonable starting point:

public float TurningSpeed = 1;
public void PerformTurn(bool turnLeft)
{
    StartCoroutine(TurnRoutine(turnLeft));
}

private IEnumerator TurnRoutine(bool turnLeft)
{
    var currentY = Player.transform.localEulerAngles.y;
    var finalY = currentY;
    if (turnLeft)
    {
        finalY -= 90;
    } else
    {
        finalY += 90;
    }

    float t = 0;
    while (t < 1)
    {
        t += Mathf.Min(1f, Time.deltaTime * TurningSpeed);
        var newY = Mathf.Lerp(currentY, finalY, t); // Or Slerp if you prefer.
        Player.transform.localEulerAngles = new Vector3(0, newY, 0);
        yield return null;
    }
}

You’ll call the PerformTurn method when you want to do a turn, passing whether to turn left or right. You can adjust TurningSpeed to control how fast it goes.

1 Like

You multiply rotations to achieve the “addition”. The sign should be *= and not +=.

Problem is Eulers introduce gimbal lock at orthogonal angles as well as that a euler repesentation of an angle can be multiple actual orientations or ways to arrive at.

That’s true, but as I mentioned, it seems they’re just rotating on the y-axis, so there would be no gimbal lock. And the code I posted wouldn’t be affected by the fact that y=-180 is the same as y=180. So, in this use case, I don’t think there’s any advantage to trying to use quaternions over using euler angles.

But that’s entirely based on reproducing the example provided in the video. If you’re going to be other, more complex rotations, then you’d need a more robust solution. But, if you’re just going to rotate on y, as in the video, I personally wouldn’t bother.

Quats will find the closest unambiguous rotation. Quaternion.Euler is a good friend when yer "cornered’ so to speak.

Thanks for help,
if you see gameplay video properly Character is rotating 90degree its right but while moving in middle or sometime in corner of the path it is rotating in a arc or may be in curved path .