3D snake classical movement

this is my code for the movement

if (Time.time - lastUpdate >=snakeSpeed)
{
var i : GameObject;
var k : GameObject;

for (var j=snakeLength;j>1;j--)
{
i = GameObject.Find("snakeBody"+j);
k = GameObject.Find("snakeBody"+(j-1));
i.transform.position = k.transform.position;
}
i = GameObject.Find("snakeBody1");
i.transform.position = transform.position;


if (right == true) {transform.Rotate(Vector3(0,-90,0)); right = false;}
if (left == true) {transform.Rotate(Vector3(0,90,0)); left = false;}
transform.Translate(Vector3(0,0,1));


lastUpdate = Time.time;
}

as you can see it’s really simple, all parts are cubes of size 1,1,1, each time frame (determined by snakeSpeed var) the procedure move the last snake piece to the position of the snake piece that is ahead, then the last body get the position of the snakeHead (which the script attached to), and then the movement of the snakeHead is performed and it works

the problem is even if I make the time (snakeSpeed) to be 0.05 it works by 20 frames for second so it doesn’t look flowish, I need help to convert this code to work by frames and not time, if I could make

transform.Translate(Vector3(0,0,0.166)); instead transform.Translate(Vector3(0,0,1));
and make all pieces follow accordingly it will be ideal for me

please share any thoughts and help I will appreciate it a lot and thank you

Typically turning and rotation use Time.deltaTime, so that movements are consistent no matter what the frame rate. Here is an example. Attach it to a block and use the arrow keys to drive it around the screen. Is this the motion of the head you are looking for?

public class SnakeHead : MonoBehaviour {
	private float fTurnRate = 90.0f;  // 90 degrees of turning per second
	private float fSpeed = 1.0f;  // Units per second of movement;
	
	void Update () {
		if (Input.GetKey (KeyCode.LeftArrow))
			transform.Rotate (Vector3.forward * fTurnRate * Time.deltaTime);
		if (Input.GetKey (KeyCode.RightArrow))
			transform.Rotate (-Vector3.forward * fTurnRate * Time.deltaTime);
		transform.localPosition = transform.localPosition + transform.up * fSpeed * Time.deltaTime;
	}
}

Here is a second script for testing the body. Attach it to a group of sphere and spread the spears out a bit. In the inspector attach one to the “head” and then attach each sphere to another so they are chained with each one having a goLeader…

public class SnakeBody : MonoBehaviour {
	public GameObject goLeader = null;

	void Update () {
		if (goLeader == null) return;
		Vector3 v3FromLeader =  transform.position - goLeader.transform.position;
		v3FromLeader = v3FromLeader.normalized * transform.localScale.y;  
		transform.position = v3FromLeader + goLeader.transform.position;
	}
}

If it were me, I would do a search on the subject of “snake” using the Google Custom Search Engine that searches everything Unity. I am sure this question has been asked and answered a few times. I am sure that this has been solved in a number of different ways, and if you get a selection of solutions, you can pick the one that works best for you.