- Home /
Strange damping issue[solved]
i have this problem where a spaceship rotation can move around a tube left or right, the ship rotates left and right fine but when i let go of the button i want a smooth stop, a bit weird to explain but basically the damping works when i let go of the right key but not the left, im probably doing a basic math error so any ideas?
if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
{
rotation = -300;
}
else if(Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
{
rotation = 300;
}
if(rotation > 0)
{
rotation -= 1500 * Time.deltaTime;
}
else if(rotation < 0)
{
rotation -= 1500 * Time.deltaTime;
}
gameObject.transform.eulerAngles.z += rotation * Time.deltaTime;
Answer by dmg0600 · Sep 19, 2014 at 06:07 PM
Could it be that you are substracting to the rotation even when it is below 0?
Change:
if(rotation > 0)
{
rotation -= 1500 * Time.deltaTime;
}
else if(rotation < 0)
{
rotation += 1500 * Time.deltaTime;
}
Haven't actually tried on the editor but it seems that is the problem.
i tried changing most these + to - and test around but without much luck, i dont really know wats the problem though?
Vector3 euler = gameObject.transform.eulerAngles;
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow) || Input.Get$$anonymous$$ey($$anonymous$$eyCode.A))
{
rotation = -300;
}
else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow) || Input.Get$$anonymous$$ey($$anonymous$$eyCode.D))
{
rotation = 300;
}
if (rotation > 0)
{
rotation -= 1000 * Time.deltaTime;
}
else if (rotation < 0)
{
rotation += 1000 * Time.deltaTime;
}
if (rotation > -10 && rotation < 10)
{
rotation = 0;
euler = Vector3.zero;
}
euler.z += rotation * Time.deltaTime;
gameObject.transform.rotation = Quaternion.Euler(euler);
This is what I meant, you were substracting ins$$anonymous$$d of adding when rotation < 0. This way you will have the same effect on both directions.
should have probably changed that, but like i said, i've seen and tested that before but didn't work at all, tested your code also but teleports my player when i let go of the button, dont think those added lines are necessary for my case; still same issue as before unfortunately :/
Ghah! never$$anonymous$$d :/ found the problem which you couldn't have known.. had a stupid $$anonymous$$athF.Clamp on my rotation limiting it from 0 to 300 ins$$anonymous$$d of -300 and 300.. noob mistake, sry bout that and thx for the help regardless
Your answer
Follow this Question
Related Questions
Smoothing eulerAngles rotation? 1 Answer
Flip over an object (smooth transition) 3 Answers
Smooth rotation on one axis only 2 Answers
Rotate Camera in Increments with Damping 2 Answers