2d Physics Engine

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

2d Physics Engine

Post by Roland_Yonaba »

Hi All,

For the past two days, I've been working on a 2D Physics Engine.
For long, I have been impressed by Physics Engines in general, and what might be achieved using them properly.
I got the awful book Game Physics Engine Development , written by Ian Millington, and I started reading it, while coding according to
my humble knowledge.

I know Love2d already features physics...But I started this for educational purposes. I am aiming understand how physics engine works, and for this,
it's not a bad idea to reinvent the wheel...

Well, here are the first results. Consider this as a pre-alpha, not even a proper release.
What I have implemented so far are just the basics ( even if it took me a while to understand how all parts works and mixing them up correctly).
- Vectors
- Particles

I have included a Demo which covers ballistics with shooter and ammos. Have fun.
I'll be pleased to have feedbacks, especially from those who are more experienced. What might be improved, pieces of advise.
Thanks in advance.

Image
Attachments
Ballistics+ParticleForceGenerators.love
2d Physics Engine Including Ballistics + ForceGenerators
(7.05 KiB) Downloaded 196 times
Physics Engine.love
2d Physics Engine Including Ballistics Demo
(5.55 KiB) Downloaded 225 times
Last edited by Roland_Yonaba on Tue Jul 05, 2011 4:05 pm, edited 1 time in total.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: 2d Physics Engine

Post by ivan »

I would call this a particle system rather than a physics engine as it seems you don't have collision response yet. :)
Personally, I'm not a big fan of vector/point objects in Lua.
I find vector objects to be a strain on the garbage collector (I guess it would be ok if you are careful not to create new vectors each frame).
Lua functions can have multiple return values which I think is a much more practicle solution to vector objects.
BTW I've been working on my own Lua physics module.
I might post it on here if anybody wants to help in getting it finished.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: 2d Physics Engine

Post by Roland_Yonaba »

Thanks,

Well, I thought implenting a vector class would nicely illustrate what I was doing.
No I do not have collisions implemented yet, but it is coming. i'm just reading my guidebook to get the concepts
and after that I make implementations.

Writing integrations methods for particle movements was quite easy, but the very big problem is setting accurate values to particles caracteristics : velocity, acceleration, damping, delta time. Great values (let's say 3, even 2) for these vectors results very quickly in enormously high values of x and y for particles position.. Then I have to work with values between 0-1 while running tests...
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: 2d Physics Engine

Post by Roland_Yonaba »

Hi,

I've brought some updates to this. I'm still at the step of particle physics, but this is growing more and more.
I have added force generators. The fact is in the previous build of my particles engine, all entities were able to move following a "realistic" trajectory, but they couldn't be affected by any force.
I have then added a new class called particle force generator. It enabled me to define the general pattern of a force, how forces are updated through time, what particles they are connected to, and how they act on them.
Then, when creating a force (class instance), it is still possible to customize this force, and then create various types of forces.

They result is not so bad. I've added a gravity force generator. Now, each particle has its own mass, and you can see the drawback of gravity when being applied on them.

Image

Download: Ballistics-Force Generators
Attachments
Ballistics+ParticleForceGenerators.love
2dPhysics Engine+Ballistics+ForeGenerators
(7.05 KiB) Downloaded 116 times
Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests