🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Programming physics with formulas and equations

Started by
15 comments, last by taby 3 years, 9 months ago

Hi, I had an idea recently to program my game physics very realistically and effective (I want to make a physics-based game).

Is it possible to use mathematical formulas and equations from real life physics and use it in my game through programming? And maybe even create your own formulas to create customized physics and rules?

I'm still researching, but I came to ask this on the forum just to not create false expectations about my idea.

Emanuel Messias, R.d.S Brazil, São Paulo
Advertisement

How about writing a tennis serve code, with gravitation, drag, and the Magnus effect?

How are you doing integration now? Are you using Euler? I find that the Runge-Kutta 4 integration method is much better, despite the extra CPU overhead.

To find all the related code, see:

https://github.com/sjhalayka/tennis

If you find the tennis code too hard to make sense of, then see this smaller, simpler Mercury orbit code:

https://github.com/sjhalayka/mercury_orbit_glut

taby said:

How about writing a tennis serve code, with gravitation, drag, and the Magnus effect?

How are you doing integration now? Are you using Euler? I find that the Runge-Kutta 4 integration method is much better, despite the extra CPU overhead.

To find all the related code, see:

https://github.com/sjhalayka/tennis

If you find the tennis code too hard to make sense of, then see this smaller, simpler Mercury orbit code:

https://github.com/sjhalayka/mercury_orbit_glut

The game has nothing (yet), I wouldn't like to think that my idea was impossible, and then program all the physics for the game and then have to reprogram physics because my idea was possible in some way.

So basically, there is no game. Just folders full of 3D models and other resources like UI elements and so on.
The Unity project is blank, I prefer to first focus on how to do physics (since the game will be around that).

Also, I'm quite a beginner at this and I'm still studying math and physics, so maybe I don't fully understand all the terms. But I will check out these links and see if I can do something with it.
(Thinking now, maybe I was supposed to put this on "for beginners" channel)

Emanuel Messias, R.d.S Brazil, São Paulo

MessiasOF said:
(Thinking now, maybe I was supposed to put this on "for beginners" channel)

No problem! Here you go…

-- Tom Sloper -- sloperama.com

Tom Sloper said:

No problem! Here you go…

Thanks and sorry for the mistake
I hope that now I get simpler answers

Emanuel Messias, R.d.S Brazil, São Paulo

Oh yeah, I did the tennis serve code in Unity and C#, using Runge-Kutta 4 integration. I can't share the code though.

Mind you, the code is 95% the same between C++ and C#, so the link that I gave you in my previous post isn't a total waste of time. The only big difference is that I use a vector in C++ and a List in C#.

MessiasOF said:
Is it possible to use mathematical formulas and equations from real life physics and use it in my game through programming?

Sure, up to a certain point. Newtonian mechanics is usual in most physics engines for games. This covers all the dynamics, cinetics and cinematics. Some fluid mechanics too, if they don't delve too much into the details. You can even simulate electro-magnetism.

MessiasOF said:
And maybe even create your own formulas to create customized physics and rules?

Keeping systems confined and energy conservative will be the main key here.

To an extend, all of it depends on what you want to simulate. Game Physics, by David Eberly might be a book you can be interested in.

For energy conservation, do you recommend a symplectic integrator, versus RK4?

https://github.com/sjhalayka/tennis/blob/d7de1e923c903c76cdaf4bb33dd3a9a7e0bf1b8d/main.h#L400

_Silence_ said:
To an extend, all of it depends on what you want to simulate. Game Physics, by David Eberly might be a book you can be interested in.

I am looking for a Portuguese version of this book, there's probably only the English version. I will read it anyway, it is really of my interest. Also, my goal is to simulate real life-based physics for a sandbox project (it doesn't have to be the most realistic thing in the world, I just thought it would be an interesting idea. I want to try this, it's a challenge that can provide me a lot of knowledge and new discoveries).

_Silence_ said:
Sure, up to a certain point. Newtonian mechanics is usual in most physics engines for games. This covers all the dynamics, cinetics and cinematics. Some fluid mechanics too, if they don't delve too much into the details. You can even simulate electro-magnetism.

I think it is enough for my project, I am happy that my idea is possible in some way. If I need anything more advanced than that (which I think is unlikely to happen) I will find some solution. My biggest interest is to be able to create customized physics.

taby said:
Mind you, the code is 95% the same between C++ and C#, so the link that I gave you in my previous post isn't a total waste of time. The only big difference is that I use a vector in C++ and a List in C#.

I'm looking at the code and thinking about how I could take advantage of it in a sandbox game, this is not a waste of time. Thank you so much (you both)

Emanuel Messias, R.d.S Brazil, São Paulo

This topic is closed to new replies.

Advertisement