A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.
47

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. ...


21

Here's the basic steps you'll need to folow: First create a world object (i.e. btDiscreteDynamicsWorld) to drive your physics simulation. You should already have a class such as GameObject that perhaps stores a model along with its bounding box and position/orientation in the world. Replace the position/orientation information with an instance of a physics ...


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

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 ...


13

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 ...


10

How to start an Architecture/Design Task: With pen and paper. Get yourself a large sheet of paper and start drawing out the components and items that will exist within your engine. What properties each entity will need so that you can model the physical interaction. You'll need to figure out what entities your code will have to deal with, which entity has ...


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 ...


10

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 ...


7

I was going to suggest that this is a hard problem because the usual formulations based on using Green's Theorem to convert volume integrals into surface integrals don't apply, and so you actually do have to provide a tetrahedral decomposition of your figure - but it turns out that that's not correct. As long as your shape is of uniform density (which is an ...


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 ...


6

Use the same time steps every time. My physics engine is set to use 33 ms time steps, and I can produce the exact same simulations that way (assuming I use the same machine.) If I use different time steps, even 1 ms more, the game will slowly diverge. You can do this with this basic loop: void update( long timeMS ) { _accumulatedTime += timeMS; ...


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 ...


6

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

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 ...


5

Generally physics engines are split into two major parts: Collision detection and collision resolution. The solver is just responsible for the second part. After your collision detection part determines which pairs of objects collide, and where, the solver is responsible for creating the correct physical response. "Iterative solver" just means that the ...


5

Read here for a good explanation of timestep http://gafferongames.com/game-physics/fix-your-timestep/ Timestep should be fixed, and this article takes a good approach and explains everything clearly.


5

You should be able have you character go up slopes without a 3rd party tool. You can attach the character controller(download it off the asset store, its free) and then you can change the angle that the character is allowed to move over (I have my player able to climb up to a 50' angle, be sure the re-angle the character though). The 2D Toolkit is ...


5

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: ...


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 ...


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