Why is this small part of code not frame independent ?

I have this code and been messing around with time.deltatime for quite a long time now, not sure why it isnt frame independant, please help.

void Update()
	{

		Vector3 velocity = bulletSpeed * transform.forward + gravity;
	
		//Debug.Log (transform.position);
		//Debug.Log (velocity);

		gravity += new Vector3 (0, -9.8f, 0);
		newPos = velocity * Time.deltaTime + transform.position;

		direction = newPos - oldPos;
		float dist = direction.magnitude;

		if(Physics.Raycast(oldPos,direction,out hit,dist,layersToCheck))
		{
			//Debug.Log("hit Object name: " + hit.collider.gameObject.name);
			Destroy(gameObject);

		}
		else
		{
			oldPos = transform.position;
			transform.position = newPos;
		}

Changing answer after I was corrected.

On closer inspection, this approach is a little curious. I’m guessing what you want is a bullet that is fired outwards in the direction of ‘transform.forward’ then moves in a curve due to gravity.

However its a little strange for a few reasons. It is kind of half way between doing things parametrically (recalculating the position every frame based off initial position/velocity) and iteratively (tracking velocity/position and incrementing every frame.

You seem to be building up velocity-due-to-gravity every frame, then adding this on to a fixed velocity value.

I would approach it this way:

Vector3 velocity;
Vector3 gravity = new Vector3(0,-9.8,0);
	
void Start()
{
	velocity = bulletSpeed * transform.forward;
}

void Update()
{
	velocity += gravity * Time.deltaTime;
	
	Vector3 new_pos = transform.position + velocity * Time.deltaTime;
}