51

On handling floating point numbers in a deterministic way Floating point is deterministic. Well, it should be. It is complicated. There is plenty of literature on floating point numbers: What Every Computer Scientist Should Know About Floating-Point Arithmetic THE NEW IEEE-754 STANDARD FOR FLOATING POINT ARITHMETIC IEEE 754-2008 revision And how they ...


34

...the inner workings of that function are generated via the appropriate mathematical formula... This will work for certain classes of problems, and the key phrase to search for is a closed-form solution. For example, in Kerbal Space Program, the motion of a spacecraft in orbit is calculated this way. Unfortunately, most non-trivial problems (e.g. ...


16

Solving this problem requires adjusting position and possibly velocity. Rigid body physics engines have a solver that march objects forward in time using Newton's laws of motion while also solving non-penetration constraints and friction. These engines can compute the right combination of linear and angular motion to create plausible trajectories. If you ...


14

First, I recommend using a free, open-source physics library like Box2D and just focusing on the aspects of your game that make it unique! If you insist on re-inventing the wheel, read on... note all physics engines are approximations, and while the method I outline below will be more accurate than your current model, Box2D's results will be far more ...


14

Spatial division is always O(N^2) in worst case and that is what complexity in informatics is about. However there are algorithms that work in linear time O(N). All of them are based on some kind of sweep line. Basically you need to have your objects sorted by one coordinate. Let's say X. If you perform the sort every time before collision detection, the ...


10

You don't need a physics engine for this because the calculations required are extremely simple! All you have to do is to apply some gravity to your player's vertical velocity, and he will automatically follow an arc when jumping. For a detailed explanation of how it works, including a demo that runs in the browser, read the following answer: https://...


10

In the vast majority of situations, calling getVelocity is a vastly preferable approach. You don't have to be polling objects on the off chance that next frame you are going to need a velocity (which requires the position from last frame). If I have 10,000 objects and nee the velocity of 10 of them on any given frame, there's no point in storing off 10,000 ...


9

The problem with your approach is, that you don't have a history of your object. You can calculate the position if you move in a direction, but what happens if you hit something and bounce back? If you accumulate from your last known position, you can handle the impact and go on from there. If you try to calculate it from the start, you have to recalculate ...


8

No. Collision detection is not always O(N^2). For instance, say we have a 100x100 space with objects with size 10x10. We could divide this space in cells of 10x10 with a grid. Each object can be in up to 4 grid cells (it could fit right in a block or be "between" cells). We could keep a list of objects in each cell. We only need to check for collisions in ...


8

However, I don't understand why it's accumulated like this when it could just as easily be gotten by changing a function. For example: getPosition = makeNewFunction() which could return something that has the signature of Time -> Position, and the inner workings of that function are generated via the appropriate mathematical formula. You can! It is called ...


8

In the case of just a simple bouncing ball, coming up with closed form solutions is easy. However, the more complex systems tend to require solving an Ordinary Differential Equation (ODE). Numerical solvers are required to handle all but the simplest cases. There are indeed two classes of numeric ODE solvers: explicit and implicit. Explicit solvers ...


8

I work for a company which makes a certain well known real-time strategy game, and I can tell you that floating point determinism is possible. Using different compilers, or the same compiler with different settings, or even different versions of the same compiler, can all break determinism. If you need crossplay between platforms or game versions then I ...


7

As far what physics engines do, I wrote an apparently decent post here: How does a collision engine work? A game engine is software that is intended to make it easy to develop a game without needing to invest in a great deal of additional technology. In other words, it implements all the basic technologies of games like graphics, physics, networking, input,...


7

The problem is this only works if movement is linear and there is no possibility of other moving objects hitting one another. As soon as you have multiple forces changing the direction in non-linear ways (eg: friction, gravity, wind) you're forced to do integration which involves slicing everything down into infinitely small time slices. This is why and ...


7

This is what I do in my N-Body simulation: particles far away can be aggregated in combined cells on a grid. (Multi-resolution Grid.) I use gravity calculations, but I am sure that charged attraction/repulsion works similarly over distance: it has the same 1/(r*r) scale. So particles in the same cell, or neighbour cell, you need to fully compute the ...


6

Here's how you might do it: Approximating movement Every physics object needs these vectors: Position: Where the object is. Speed: How its position is changing. Acceleration: How its speed is changing. So, intuitively, you need to do this sort of thing every frame to every physics object a: a.speed += a.acceleration a.position += a.speed Pitfalls: ...


6

I'm not entirely sure that you understand what the article means by a fixed timestep. requestAnimationFrame is defined as: Tells the browser that you wish to perform an animation; this requests that the browser schedule a repaint of the window for the next animation frame. The amount of time that passes between each invocation of the function varies ...


6

Your solver needs multiple iterations (aka sequential impulse) over its contacts. Treat each contact point independently and calculate the impulse to resolve its contact constraint for that iteration. This may cause previously resolved contact points to be pushed back into the colliding object, but not by as much as the initial penetration. Perform ...


6

When you say 'synthesis' do you mean pure analog/additive/FM synthesis from scratch, or would a sample-based approach be acceptable? If you can't use combinations of real-world audio samples then this is more complicated process. Trying to generate truly realistic sounds through synthesis isn't the standard way that most game/virtual instruments/sound ...


6

The input it speed, mass, and time, the output is new speeds. Sometimes rotation/angular momentum is an input and output too. Essentially Physics engines try to simulate the effects of both gravity and collisions. For better physics engines that means they include both permanent and temporary deformation of objects, including splitting objects into multiple ...


5

You should probably start with an open source 3d physics engine like Bullet. Remember that games that have funding can hire professionals that are well versed in kinematics that can draft models in math-lab and then have programmers implement them in the code. So the best way to fully implement a systems like this would involve learning about cars and ...


5

One solution I have found when using position correcting is to have a few iterations and vary the strength with each iteration. doPhysics(); int num_iterations = 5; for(int iteration=0; iteration<num_iterations; ++iteration) { float strength = float(iteration+1)/num_iterations; correctPositions(strength); } So the first iteration has a strength ...


5

Your problem lies in the fact that you have no "resting" state for your bodies. Any physics system has an amount of energy, be that kinetic, thermal, and so on. In reality, solid object deform slightly, and tranform some kinetic energy into heat, though it is hardly measurable. It's also worth noting that in reality there is no such thing as a completely ...


5

I'm not sure if this is the type of answer you're looking for, but an alternative might be to run the calculations on a central server. Have the clients send the configuration to your server, let it perform the simulation (or retrieve a cached one) and send back the results, which are then interpreted by the client and processed into graphics. Of course, ...


4

I guess this kind of ends up being a non-answer... I think sometimes it depends on the implementation and the basic approach used for collision detection and resolution (which is like 80% of a rigid body physics engine, I guess). It's funny because I just hit this problem the other day in my own home-grown physics engine and threw an object into NaN space. ...


4

This looks very similar to a problem I once had when making my own physics hack, although I can't really see from your code if this is the case here. My problem was that when an object collided at a slow speed my collision handling didn't move it enough away from the collision (so it didn't solve interpenetration). That mean that a second collision would be ...


4

In case you are having troubles with small numerical values, I suggest that you simply scale everything down. You might even not use "real" measurment units, but just some "generic" units that only make sense inside the engine. The first option, scaling down, would require that you use millimeters or centimeters as a base measurement unit. Your cube's ...


4

Q. Does the scripting language have to be Javascript? A. Yes. There are other somewhat supported scripting languages, but JavaScript is by far the easiest to get into, most widely supported, and most widely documented. In terms of JS toolkits available, jQuery is certainly an option. So is Dojo Toolkit; with its AMD design scheme, it's (arguably) the better ...


4

I started out with Baraff too but it's a bit dated by now. What you need is iterative solvers and the best paper imo on that is Erin Catto's Iterative Dyanmics. You have all you need in there to implement your physics engine. You can dig a bit into Erleben's PhD thesis if you need more details (like joints and more math stuff), but that's pretty much it. I ...


Only top voted, non community-wiki answers of a minimum length are eligible