Why the first time everything is okay, movement works as need, and after this movement, speed is up. I do nothing to change speed, how it works? I use SpriteRenderer on an island and Camera movement that moves to the desired object.
Is something changing your speed variable? To find out, make it a const
and see if the problem goes away.
Also, it’s difficult to see code in a video, so instead please use code tags: Using code tags properly
Generally, to help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.
Doing this should help you answer these types of questions:
- is this code even running? which parts are running? how often does it run?
- what are the values of the variables involved? Are they initialized?
Knowing this information will help you reason about the behavior you are seeing.
The first time it runs 120 times, the second (when the speed is faster) 5 times. I made const var and it doesn’t help.
I tried a lot of solutions, it’s not a typical error, I don’t know how to fix it. Probably the reason is that I’m using Vector3.MoveTowards when works in 2D. But why the speed is increasing?
No, it has nothing to do with that. Vector3D can handle 2D motion too.
Hard to say until you post some readable relevant code using code tags.
I fixed it by using Vector2.MoveTowards. My Camera and Sprite have different Z positions, maybe it was a reason. The first time it moved slowly because it also needed to move along Z, and when it on Z, it moves faster.
Okay, I stand corrected… that’s probably it if you were starting from way up by the camera and then moving into the scene, yeah, 3D vs 2D makes a difference with move-towards. My bad.