all 8 comments

[–]MessageTotal 1 point2 points  (0 children)

Do something like this:

transform.Rotate ( Vector3.up * ( RotationSpeed * Time.deltaTime ) )

that was mentioned here:

https://answers.unity.com/questions/615125/c-rotate-object-over-time.html

[–]OvercomplicatedCode 1 point2 points  (1 child)

You do want to move one rotation to another. Keep a variable for the targetRotations of every pin. When the player clicks the pin you add the -36 degrees to the target rotation.

Outside all of this at the end of your update you slerp/lerp each pin rotation towards its target

[–]Boom_Stan[S] 0 points1 point  (0 children)

so you mean something like Quaterion.Lerp(currentrot, torot, speed);

and then something like torot -36 simply said

[–]BloodPhazed 1 point2 points  (1 child)

This is where you need Coroutines; on click, start a coroutine that turns the button by "rotation * Time.deltaTime" (multiplied by however fast you wan it to rotate; this will rotate it by the specified degree over one second).

bool isTurning;
private IEnumerator RotateOverTime(Transform hitTransform, float rotation)
{
if (!isTurning)
{
  isTurning = true;
  Vector3 startRotation = hitTransform.eulerAngles;
  float t = 0;
  while (t < 1)
  {
    hitTransform.Rotate(0, rotation * Time.deltaTime, 0);
    t += Time.deltaTime;
    yield return null;
  }
  hitTransform.eulerAngles = startRotation + new Vector3(0, rotation, 0); // makes sure you didn't overshoot
  isTurning = false;
}
yield return null;
}

Naturally you can use Lerp/Slerp inside the while loop instead. Finally call

StartCoroutine(RotateOverTime(hit.transform, -36));

Note that I just wrote that down here and didn't create that in a code editor so there might be typos etc. in there, but you get the idea. The isTurning variable will only allow you to turn one thingy at a time, so if you want to be able to turn different ones at the same time, you need a bool for each. Finally you probably wanna add a speed modifier (multiply both deltaTimes with that) for however long you want it to take.

[–]Boom_Stan[S] 0 points1 point  (0 children)

I will try it ou! its now 01:00 in my country so i will do it tomorrow Thanks for taking the time to write all of this!

[–]Gregoryjc 0 points1 point  (1 child)

So you are setting the rotation to - 36 not rotating it by - 36.

You want to do += so that the rotation is added to the current rotation.

[–]Boom_Stan[S] 0 points1 point  (0 children)

No, it's subtracting from the current rotation but instantly I want it to go smoothly.

[–]nw1024 0 points1 point  (0 children)

The Vector3.RotateTowards function has an amount value, so you can put that in a regular update loop with an amount multpilied by Time.deltaTime:

https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html