# How do I change speed and not effect time

X = Sin(time * speed) and Y = Cos(time * speed). Where speed just makes the animation faster it also effects the position. So when changing speed it’ll cause my animation to teleport to its new position. How can I keep time relative to the speed so when speed is changed it’ll continue to move down the unit circle without teleporting.

There are many different ways it can be done.

• Change formula from angle=timespeed to angle=timespeed+phaseOffset . And when changing speed solve the equation for newPhaseOffset which would maintain the angle.

• Update angle incrementally instead of angle=timespeed do angle = angle+timeDeltaspeed. This approach is probably the simplest and most robust.

• Rotate existing position instead of pos=v2(sin(angle), cos(angle)) doing rotation=FromEuler(0, 0, timeDelta*speed), pos = pos * rotation

2 Likes

The above is how I would do it. Have your own notion of “time”

``````private float myTime;
``````

and in your Update(), update it by whatever scale you like:

``````myTime += Time.deltaTime * speed;
``````

And then use myTime in your trig calls WITHOUT multiplying it by speed. That way only the changing of it will get faster, and you won’t jump around in phase.

1 Like

Sorry for the late reply. Thank you so much I was able to get it working with your 2nd method Karliss Coldwild. It seems I was looking at it the wrong way. I wasn’t really seeing it as in terms of angles but of 2 separate values. So simply incrementing on the angle like you said works perfectly. Again, Thank you so much for the help both of you I’m sure your method Kurt would’ve worked as well.

Here’s what the result looks like if your curious. It’s the gun animation.