• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Q: Implementating a Physics System

## Recommended Posts

Sphet    631
Hello, I''ve started working on a really small simulation that I hope will lead to other projects. What I am trying to do is have a collection of conveyor belts (defined simply by two points and a velocity vector), and a box. The box should obey the laws of gravity, falling from one conveyor belt to the other. What I am wondering is how best to implement the physics engine. Although all of my data is stored as 3D point data (I am using direct 3d for visualization), I am only concerned with a 2D side view. Does the normal collision sphere followed by triangle intersection test seem the best way to go? Can someone give me a basic rundown on the right way to do a physics engine.. how does one decide what order to check all the objects in the world, when is it done, etc. Also, if I have a couple of conveyor belts that are attached in a V, how do I figure out that, as movement on one length of the belt is finished, the box moves to the next.. I''m pretty new to all this, having implemented simple gravity in 2D side scrollers in a really simple way before. Many thanks.

##### Share on other sites
liquiddark    350
If your boxes aren''t rotating as they fall and your belts are horizontal, just use the standard box test. Roughly, in pseudocode:
if (bottom of box <= top of collision object) &&   (top of box >= top of collision object) &&   (left side of box is within horizontal range of collision object) ||   (right side of box is within horizontal range of collision object)   // Collide objects here

Otherwise, a circle test should work just fine. It''s like the sphere test but without the z-value. Note that you must constrain your objects'' speed per step or else use a trace-style intersection wherein you test the volume through which an object moves rather than the object itself. This applies to collision volumes as well.

A good physics engine will have a clock independent of (but preferably as fast as or faster than) its graphical counterpart. Testing collisions in the immediate area only (and, if you want, in "action areas", ie areas where interesting things are happening) will reduce the required processing power. I would suggest to you that you try using a graph of objects and a list of active objects. Populate the list with all active objects within the graph, and if a particular interaction affects a deactivated object, reactivate it, but wait until the next time step to work out the effect. Make sure that all your reactions are constrained, if possible, since you otherwise will get perpetual rattling, by which I mean objects will interact every frame and will not settle.

If you take a look at many last-generation FPS engines, a box or cylinder test is all that is used - no triangle intersection is calculated. Of course, for a physics-heavy game (see Hitman), triangle intersection is more important.

As to the V arrangement, use the circle test and use a physics clock to run your system. Run the clock at all times, of course.

ld