Position jumping for one frame.

Hi signed up for a new account as couldn’t reclaim old one. Anyway.

I have a problem that has me totally stumped.

I have implemented a replay function. I have an array of positions and at set increments i move my character along this path.

However each time I update the position for one frame the character appears ahead of itself. When i step through using the debugger its position is always correct but its visibly ahead of itself. This gives its movement a flickering appearance.

		flightTimer += (Time.smoothDeltaTime);
		
		if(flightTimer >= (OverController.recordIncrement))
		{

			flightTimer = 0.0f;
			flightCounter ++;

		        this.transform.eulerAngles = flightRotations[flightCounter];
		        this.transform.position = flightPositions[flightCounter];
	
		}

That’s the code. Can anyone tell me WTF is going on please? lol

I’ve tried so many different solution, including creating a fake flight path where the data is simple to ensure its not the flight recording. I’ve debugged the positions and when it flicks forward the position is the same as when it flicks back. I’ve turned off animations. Substituted the player for a simple cube , moved the code to LateUpdate or even FixedUpdate. No difference.

Im hoping it’s something stupid i’ve missed so everyone can laugh at me and i can stop banging my head off the wall.

Thanks in advance.

I’m a little confused. Are you saying that when the character’s at for example) position 10, it appears to be at 11?

All I can guess is to ask if you’re counting from 0 or 1, because this code will start it at 1; if the initial value of flightCounter is 0, than the first sampling will be from index 1 because it increments before polling the array.

Every time i update the position for one frame it jumps forward then back to where it should be. But the GameObjects position in the inspector, or if I put a watch on it in the debugger doesn’t change.

Is another entity trying to control the position? Another controller script? A non-kinematic RigidBody? The editor itself?

Is there any way I can take a look at the whole project or is this a professional thing you can’t share?

Im afraid I can’t share.

I took the basic code you see above and applied it to a simple cube with no phsyics etc attached and nothing else interacting with it and got the same response.

It’s very frustrating!

This sounds so familiar it hurts. I’m going to see if I can reproduce it.

I wrote this hopefully analogous code to reproduce it (since I don’t have all your code) and did not get a reproduction:

public class Repro : MonoBehaviour {
	
	Vector3[] positions;
	
	private const float stepTime = 0.5f;
	
	void Start ()
	{
		positions = new Vector3[16];
		for(int i = 0; i < positions.Length; i++)
		{
			positions[i] = new Vector3((float) i, 0f, 0f);
		}
	}
	
	private float step = 0f;
	private int j = 0;
	
	void Update ()
	{	
		step += Time.smoothDeltaTime;
		
		if(step > stepTime)
		{
			step = 0f;
			
			j++;
			
			if(j >= positions.Length) j = 0;
			
			transform.position = positions[j];
		}
	
	}
}

Can you please drop it directly into a file and attach it to a new cube and see what it does?

I tried doing basically that before. Your script worked fine.

I stripped out some stuff.

And altered my camera code and it seems to work now, still not 100% sure what the problem was , which bugs (haha) me.

Anyway thanks for having a look , sometimes a fresh eye helps when your going mad lol

lol, well a win’s a win. Good luck.