0
\$\begingroup\$

It should be kind of slowly standing effect. The FPSController is starting at rotation: X = 7 Y = 112 Z = -31

Rotation

The problem is that i have on the FPSController a script that i use the mouse to rotate the camera around. And i see that when i rotate the camera the center point of the FPSController seems stuck on this angle even if i change the rotation to 0,0,0

If i start the game running it when the rotation of the FPSController is 0,0,0 then it's standing but when i start the game with 7,112,-31 and then moving the mouse it keep be locked on this rotation values. And i want it to slowly return to the original 0,0,0

I tried when the game is running and the fpscontroller rotation set to 7,112,-31 to change it to 0,0,0 but it keep staying at the rotation of 7,112,-31

What i want is that the fpcscontroller to stand. I don't think that i need to change it's position but only the rotation.

In my script i tried this: At the top:

public FirstPersonController fpc;
public float speed = 10F;

Then in the Update:

void Update()
{
  fpc.transform.rotation = Quaternion.Slerp(fpc.transform.rotation, 
  Quaternion.Euler(0, 0, 0), Time.deltaTime * speed);
}

But it didn't return it to the standing position it keep it on the current rotation 7,112,-31

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

I think I didn't get quite right your issue, but I'll try...Maybe you could store the initial rotation on Awake:

Edit: Now I got your issue. You are using the interpolation (Slerp) wrong. It is based on the formula:

P = P0 + (t * (P1 - P0)), 0 < t < 1

So it is an interpolation normalized between 0 and 1, the problem with your function is that (Time.deltaTime * speed) is always giving a delta of frames duration (usually 0.02) multiplied by your speed, that is never going to reach 1 to have your rotation at the Quaternion.identity. You should play with a float that each frame gets summed until it reaches 1, giving a quick example:

Quaternion initialRotation; /// <summary>Here you store the initial rotation.</summary>
float t = 0.0f; /// <summary>Time reference for the interpolation.</summary>

/// <summary>Called on MonoBehaviour initialization.</summary>
void Awake()
{
    initialRotation = transform.rotation;
}

/// <summary>This MonoBehaviour's Tick at each frame.</summary>
void Update()
{
    transform.rotation = Quaternion.Slerp(initialRotation, Quaternion.identity, t);
    t += (Time.deltaTime * speed);
}

So you could use that value initialized on Awake, the slerp takes that rotation, since interpolating between the actual rotation wouldn't give the expected results. We are using Quaternions here, since what there is shown on the inspector is an Euler Angle representation of the quaternion, and its less recomended to play with eulerAngles. So, if you want your FPC to be at a (0,0,0) rotation, then set its transform.rotation to Quaternion.identity.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .