View unanswered posts | View active topics It is currently Sat Dec 28, 2024 3:03 pm



Reply to topic  [ 3 posts ] 
 How should I simulate acceleration? 
Author Message
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post 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?


Sat Feb 18, 2012 2:17 pm
Profile
User avatar

Joined: Fri Feb 16, 2007 8:43 pm
Posts: 1695
Location: AH SHIT FUCK AUGH
Reply with quote
Post 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. :-o
Also, both of these give you a vector with the acceleration.


Sat Feb 18, 2012 8:12 pm
Profile WWW
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post Re: How should I simulate acceleration?
Thanks for the code! I'll try it out.


Sun Feb 19, 2012 3:53 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.030s | 13 Queries | GZIP : Off ]