Data Realms Fan Forums http://45.55.195.193/ |
|
How should I simulate acceleration? http://45.55.195.193/viewtopic.php?f=1&t=30337 |
Page 1 of 1 |
Author: | ryry1237 [ Sat Feb 18, 2012 2:17 pm ] |
Post subject: | How should I simulate acceleration? |
In my physics booklet, acceleration is the change in velocity divided by time. In CC, time would just be the interval between game calculations, but how should one go about finding the change in velocity? |
Author: | Shook [ Sat Feb 18, 2012 8:12 pm ] |
Post subject: | Re: How should I simulate acceleration? |
Velocity in current frame minus velocity in previous frame. That'd give you a per-frame acceleration to work with. With some shenanigans, you could work out a dynamic average acceleration, though any acceleration in CC is likely to be either constant or instant. Lua example for per-frame acceleration: Code: function Create(self) self.oldVel = self.Vel; --replace self.Vel with Vector(0,0) if you want to include firing velocity as acceleration end function Update(self) self.acc = self.Vel - self.oldVel; --find acceleration of this frame --sneaky stuff goes here self.oldVel = self.Vel; --set up next frames measuring of acceleration end If you want to include the mentioned dynamic average (from start to end), here's how i'd do it: Code: function Create(self) self.oldVel = self.Vel; --replace self.Vel with Vector(0,0) if you want to include firing velocity as acceleration self.iterations = 1; --starting with one frame of collected data self.totalAcc = Vector(0,0); --we have no acceleration to begin with end function Update(self) self.acc = self.Vel - self.oldVel; --find acceleration of this frame self.totalAcc = self.totalAcc + self.acc; --summing up all acceleration so as to make an average local average = self.totalAcc/self.iterations; --dividing sum of acceleration with the number of frames of collected data for a neat average --sneaky stuff goes here self.iterations = self.iterations + 1; --add one to the number of frames for the next average self.oldVel = self.Vel; --set up next frames measuring of acceleration end I think. Mostly i'd just be applying acceleration to things though, because that tends to destroy more things than finding acceleration. Also, both of these give you a vector with the acceleration. |
Author: | ryry1237 [ Sun Feb 19, 2012 3:53 am ] |
Post subject: | Re: How should I simulate acceleration? |
Thanks for the code! I'll try it out. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |