Hello
I wanted to deactivate pitch- and roll-rotation when the ship is at the x- and y-borders. I think this shows the player more clearly that he can’t move any more left/right or up/down.
Therefore I adjusted my code for ProcessRotation, so pitch is only executed when the local y-position is between the border values and likewise for roll and the x-position.
So it looks like this:
void ProcessRotation()
{
float xBorder = Mathf.Abs(transform.localPosition.x);
float yBorder = Mathf.Abs(transform.localPosition.y);
if(xBorder < 10 && yBorder < 5)
{
float pitchDueToPosition = transform.localPosition.y * pitchFactor;
float pitchDueToControlThrow = yThrow * controlPitchFactor;
pitch = pitchDueToPosition + pitchDueToControlThrow;
roll = xThrow * rollFactor;
yaw = transform.localPosition.x * yawFactor;
transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
}
else
{
mildYaw = transform.localPosition.x * mildYawFactor;
transform.localRotation = Quaternion.Euler(0, mildYaw, 0);
}
}
The good thing is that my little extension works. But I would like to further improve my code and smoothen the transitions.
Are there any suggestions on how to slowly translate between the current rotation-value and 0?
It’s especially obvious when the ship reaches the y border, then the x-rotation snaps from somewhere around ± 20 to 0
Many thanks in advance!
Thomas