Skip to main content
gamedev.net
🔒 Locked

An Idea

Started by AfroFire 2 replies 800+ views
Original Post
AfroFire
AfroFire
Hello, I'm creating a 2D Engine, and I'm just kind of curious as to how objects should act against other objects and all im going to do is explain my idea and I was hoping you guys could critique it here. Basically I have a vector class, then I have an object class. Every object class contains a vector, and a list of force vectors acting against it. That's basically it. How do other people calculate outside forces acting on objects? Is this method to slow? Thanks in advance.
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
Joakim_ar
Joakim_ar
I think your method would be fast enough, as it's only a matter of three addition per acting force vector. I had a similar idea some time ago, but I never got around to implement it, so I can't know for sure.

In my current project, which is 3d in the sence of vectors (but really it's tilebased 2d with some few 3d tricks), each object has three vectors: Position, Velocity and Acceleration. Each tick Acceleration is applied (added) to Velocity and then Velocity is applied to Position.

If your list of force vectors does not change very often, you could simply add this list of vectors and keep it in one Acceleration vector. That would be faster no doubt. But if you need multiple dynamic force vectors that needs to be recalculated each tick, your idea sounds like a good solution to me.
AfroFire
AfroFire
Thank you very much.
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
Gaffer
Gaffer
the standard technique when using a simple integrator is just to have a single accumulator value for force, and a method applyForce(const Vector &force) which simply adds the force param to the accumulator

it gets trickier with higher order integrators, in which case i prefer to do all force calculations inside the object on demand given a physics state, instead of applying forces to the object externally -- this is a better solution overall, but an accumulator will get you off to a decent start with a simple euler integrator

cheers

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.