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.