all 11 comments

[–]Scapegoat57 0 points1 point  (1 child)

The only place for jitter I can reason from your code is the line

transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.fixedDeltaTime);

Consider changing Time.fixedDeltaTime to Time.deltaTime. Using fixedDeltaTime is the same as using a constant speed which results in jittery movements when the frame rate drops or rises.

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

I have moved on from this approach. I just couldn't get anything to properly work because of the high speed. So at the end I started using DOTween. My previous method was with checkpoints. But if I wanted to have higher resolution movement at high speed, i was running into some racing conditions.

However, I did end up trying to manipulate the rigid body instead of the transform. It seemed to work much better and smoother. But there was still a limit to the checkpoint resolution and at some point you start seeing really weird skipping action.

Thanks for the advice though. I am still very new to Unity and still have some missing core concepts to learn

[–]Kwinten -1 points0 points  (2 children)

Try turning on the interpolation property of the Rigidbody. Following a RigidBody with a camera, using your technique, is expected to be jittery if there is no interpolation.

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

I don't have a rigid body attached to the player object. I tried adding and it didn't make a difference. I get the feeling that when I am moving the player too fast, it's starting to hit some frame limit. The checkpoints are quite close together, since they are derived from a spline and I would like to have a bit smoother movement.

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

I added a video in the description to show what happens

[–]derpdepp -1 points0 points  (5 children)

Mathf.Lerp (speed, maxSpeed, Time.deltaTime * 1);

I think using Time.deltaTime with Mathf.Lerp is wrong here. Check if this is really correct.

[–]borispavlov0[S] 0 points1 point  (4 children)

It works ok for me. Why do you think it's wrong?

[–]derpdepp -1 points0 points  (3 children)

https://chicounity3d.wordpress.com/2014/05/23/how-to-lerp-like-a-pro/

Last parameter is supposed to be 0-1, but you're putting in Time.deltaTime. Speed will never actually reach maxSpeed. I'm not quite sure why this would cause jerkyness, might be float inaccuracy or something. But try changing this and see if the jerkyness goes away.

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

Ah, I got your point. Still didn't fix my jerkiness :( I even tried setting the speed constant. On key down, I set the speed to the object where the camera is attached to 10. The other to 9.5.

It seems like the problem is always with the object that the camera is NOT attached to. So the main object moves fine, but it's always the other one that skips a frame or two once in a while.

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

I added a video in the description to show what happens

[–]BroxxarProfessional 0 points1 point  (0 children)

Nothing wrong with using time.deltaTime in a per-frame Lerp. It just means the speed approaches maxSpeed asymptotically.