Hi @Donwaleed
You can apply for a residence permit according to paragraph 28, section 1, number 3 of the Residence Law (Aufenthaltsgesetz. This is for parents of German children. When you have the Vaterschaft, send it with an application for residency to your local immigration office (Ausländerbehörde). Ideally you will also do a declaration on shared custody (Sorgerecht) which you should also send.
While you are entitled to a permit, the authorities may insist on you leaving Germany and coming back with the correct visa. As the child is not born, it may not be possible to avoid this. The closer it is to the birth, the more likely you will be allowed to stay and be issued with a permit without having to leave the country. Once the child is born, you have a clear right to have your application processed without leaving the country. This is because the courts have ruled that it is not reasonable for a young child to have to be separated from a parent due to a visa process.
For the time period leading up to birth, however, it is less clear. You can **** at my answer here to a question about visas during pregnancy for some guidance also:
https://***.wefugees.de/816148/pregnant-with-a-german-baby-can-my-visa-process-be-expedited
Best,
Éanna