![]() |
| | #1 | |
| The larch Join Date: May 2006
Posts: 3,082
| Acceleration and time delta Currently I have the following (this is for a bounding circle of several particle-like objects that should move at the same speed but in different directions, to optimize collision checking): Code: speed *= acceleration attack_circle.r += (speed * delta_time) The problem is, it doesn't take delta-time into account when calculating the speed change, and hence, the slower the game actually runs, the further the circle expands.
__________________ I might be wrong. Quote:
| |
| anon is offline | |
| | #2 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Since acceleration = (delta speed)/(delta time), then you should be able to solve for delta speed to get (delta speed) = acceleration*(delta time). |
| tabstop is offline | |
| | #3 | |
| The larch Join Date: May 2006
Posts: 3,082
| Ok. I printed out some computed values what happens at 60 fps in the game: Code: 0.205800 3.430000 -0.004200 -0.00025200 0.201684 6.791400 -0.004116 -0.00024696 0.197650 10.085572 -0.004034 -0.00024202 0.193697 13.313861 -0.003953 -0.00023718 0.189823 16.477583 -0.003874 -0.00023244 0.186027 19.578032 -0.003796 -0.00022779 ... 0.067745 116.174625 -0.001383 -0.00008295 0.066390 117.281133 -0.001355 -0.00008129 0.065063 118.365510 -0.001328 -0.00007967 0.063761 119.428200 -0.001301 -0.00007808 0.062486 120.469636 -0.001275 -0.00007651 So it appears that the (desired) acceleration is not constant, and the change of acceleration doesn't appear to be linear either. The math is getting quite hard. I wonder if I could find a linear equation to calculate the drop of acceleration, to approximate current behaviour, and hence get something like the following? Code: acceleration += acceleration * delta_time * some_constant speed += acceleration * delta_time r += speed * delta_time
__________________ I might be wrong. Quote:
Last edited by anon; 10-18-2009 at 01:33 PM. | |
| anon is offline | |
| | #4 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Not sure what you're modeling. If you're doing physics, then generally the acceleration is calculated from position, and you go from there. For instance, when I do spaceships going around a planet, the pseudocode looks like Code: direction_to_planet = spaceship.position - planet.position; acceleration = G * direction_to_planet / pow(length(direction_to_planet,3)); spaceship.position += dt * spaceship.velocity; spaceship.velocity += dt * acceleration; |
| tabstop is offline | |
| | #5 | |
| The larch Join Date: May 2006
Posts: 3,082
| Basically it is just a circular "burst" of some particles from a source. There's no real-world gravity here.
__________________ I might be wrong. Quote:
| |
| anon is offline | |
| | #6 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Well, I can't say what formula governs your numbers since I don't know how you generate them. If you had some physical thing going on behind your particles, then that would give you your acceleration. If you like the picture you have and want to find a formula, it might not be a bad idea to load that file you have into a spreadsheet and run a regression on it and see what happens. |
| tabstop is offline | |
| | #7 | |
| The larch Join Date: May 2006
Posts: 3,082
| Thank you. I think Excel should be able to figure out the formulas behind the values. Also, when it comes to physics, I think this might remind of friction (drag). And eventually, it won't need to be exactly the same, just as long as the result is the same at different FPS.
__________________ I might be wrong. Quote:
| |
| anon is offline | |
| | #8 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| The method of simulating acceleration and velocity is always the same. The only thing that differs between games is the way the force is calculated. In vector math/pseudocode, this is how the update happens at each timestep: Code: UpdateAllForces();
foreach( object )
{
object->Acceleration = object->Force / object->Mass;
object->Velocity += object->Acceleration * deltaT;
object->Position += object->Velocity * deltaT;
}
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #9 | |
| Super Moderator Join Date: Aug 2001
Posts: 7,470
| Quote:
__________________ If you aim at everything you will hit something but you won't know what it is. Last edited by Bubba; 10-19-2009 at 04:35 PM. | |
| Bubba is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Accuracy changes under different modes | sundeeptuteja | Tech Board | 3 | 07-08-2003 11:02 PM |
| Now's the time to try Allegro (newbie and pro alike)! | Justin W | Game Programming | 19 | 12-23-2001 08:47 PM |