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;

1 Answer

1

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?

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! nevermind :/ found the problem which you couldn't have known.. had a stupid MathF.Clamp on my rotation limiting it from 0 to 300 instead of -300 and 300.. noob mistake, sry bout that and thx for the help regardless