Are my physics calculations correct ?

public void UpdateVelocity()
{
this.acceleration = Physics.gravity;

        this.velocity += this.mass * this.acceleration * Time.deltaTime;
        this.velocity *= Mathf.Clamp01(1f - this.drag * Time.deltaTime);

        //this.velocity = this.velocity + Physics.gravity * this.mass * Time.fixedDeltaTime;
        //this.velocity = this.velocity * (1 - Time.fixedDeltaTime * this.drag);
    }
    public void UpdatePosition()
    {
        this.position += this.velocity * Time.deltaTime;
    }

I had to build my own physics script please dont ask why. Rigidbody component is just trash for my realistic bullet physics and object pooling.

Will this work correctly ? I wanna change drag to be for example bullet drag with external ballistics

Well, in principle yes, actually, no ^^. One of the major issues is that you can not really make calculations that have a higher degree than 1 framerate independent. Any linear change can be made framerate independent by multiplying by deltaTime. However the position change which is based on the velocity change would be a quadratic movement. The effect is that with lower framerates the distances moved over the same amount of time would be greater compared to a high framerate.

That’s the main reason why physics are run on a fixed timer ( in sync with FixedUpdate) so you get the same results regardless of the framerate.

So if you run this in FixedUpdate it would be similar to Unity’s Physics. However you have an error in the way you apply the acceleration. There is no mass involved. The gravity value is an acceleration that is independent of mass.

On the surface of earth we have a gravitational acceleration of about 9.81 m/s². Yes, the gravitational force depends on both masses. However the mass of the object cancels when you calculate the acceleration it receives

F = G * M * m / d²

“d” the distance from the earth center is essentially constant since it doesn’t really change much, even when you go up a few km. The acceleration can be calculated by

F = m * a
// therefore
a*m = G * M * m / d²
a = G * M / d²

As you can see “m” the mass of the object cancels on both sides. So G * M / d² gives us a constant acceleration near the surface of the earth and it’s about 9.81m/s²

Note it’s possible to make a pure quadratic behaviour framerate independent with a small trick. However since you also want drag in the mix, that would not help at all. So you really need to do the physics calculations in a fixed timestep. If you need a higher precision simulation you can either crank up the fixed timestep, or use my CustomFixedUpdate class.

Finally keep in mind the way Unity applies drag is a very crude and simple solution to simulate drag. It does not resemble anything in the real world. Real world drag depends on several factors. The projected area in the movement direction through the air, the form coefficient and the velocity squared. Unity’s drag is just a simple percentage fall off.

You may have your reasons to implement your own physics, however I highly doubt it would be anything better. Unity uses Nvidia PhysX for 3d physics. It’s a highly optimised and reliable physics simulation for games. Yes, it does not resemble real world physics because that’s almost never needed. If you really want to create a realistic behaviour, you have a long way ahead. Proper physics simulation is incredible complicated ^^. Especially when it comes to rotational inertia.

Actually I dont really need high accurate physics simulation.

I just wanna my bullet script to have this kind of physics

implemented onto bullet: bullet drag based on drag coefficient, wind direction (winch also changes velocity of the bullet), temperature, density

so it will just behave how it should

I found some equations but I dont know how to implement them, they are hard

and it would be nice to have physics implemented for spacetime curvature of the earth but for now im just using flat world