Data Realms Fan Forums
http://45.55.195.193/

Acceleration Variable?
http://45.55.195.193/viewtopic.php?f=73&t=17133
Page 1 of 1

Author:  CaveCricket48 [ Sat Nov 14, 2009 7:01 pm ]
Post subject:  Acceleration Variable?

Is there a Lua variable for an object's acceleration?

Author:  TheLastBanana [ Sat Nov 14, 2009 8:26 pm ]
Post subject:  Re: Acceleration Variable?

No, there isn't.
If you want to find the object's acceleration since last frame, then include the variable "self.lastVel" in the Create event. At the end of each Update cycle, add this:
Code:
self.lastVel = Vector(self.Vel.X,self.Vel.Y);

That makes it so that it's a new vector and not just a pointer to the old one.
Then, whenever you need to check acceleration, just get self.Vel - self.lastVel, and the X and Y values will be X and Y acceleration respectively.

Author:  CaveCricket48 [ Sat Nov 14, 2009 8:43 pm ]
Post subject:  Re: Acceleration Variable?

Is there a way to get this in m/s^2 accuarately? As in, when the acceleration is called for, it gets the current velocity and the velocity 1 second before?

Author:  TheLastBanana [ Sat Nov 14, 2009 8:45 pm ]
Post subject:  Re: Acceleration Variable?

Well, before we go any further, why do you need that?

Author:  CaveCricket48 [ Sat Nov 14, 2009 9:04 pm ]
Post subject:  Re: Acceleration Variable?

I need to calculate the amount of force an object has. According to my Matter and Energy teacher, the equation is "Force = mass * acceleration".

Author:  Grif [ Sat Nov 14, 2009 9:42 pm ]
Post subject:  Re: Acceleration Variable?

Objects within CC (at least, bullets) virtually never have acceleration, only constant velocity. Thus, according to newtonian physics, they have a net force of exactly 0.

Author:  TheLastBanana [ Sat Nov 14, 2009 10:00 pm ]
Post subject:  Re: Acceleration Variable?

The fact is that this game is not really modeled after real-world physics. An object's velocity is almost always constant. Gravity does work using acceleration in the game (m*s^), but that's a different thing. I'm still not sure why you would need to calculate real-world force for this when you've already got values of mass and speed at your disposal.

Author:  CrazyMLC [ Sat Nov 14, 2009 10:00 pm ]
Post subject:  Re: Acceleration Variable?

I think you could write code to do what you want, if I am not misunderstanding.

I think this might do what you want.
Code:
function Create(self)
 self.LastVelocity = 999
 self.Acceleration = 0
end

function Update(self)
 self.CurrentVelocity = self.Vel
 self.CurrentVelocity - self.LastVelocity = self.Acceleration
 self.LastVelocity = self.Vel
end


EDIT: Oh, so I misunderstood the purpose. Nvm, nothing to see here.

Author:  TheLastBanana [ Sat Nov 14, 2009 10:03 pm ]
Post subject:  Re: Acceleration Variable?

That's basically what I posted earlier, but it doesn't work. You're making self.lastVelocity a pointer to self.Vel, meaning it just directly reads from self.Vel when you access self.lastVelocity. We want to store self.Vel's values, not access it again next frame, so use the technique I had above of setting the X and Y velocity individually.

Author:  CaveCricket48 [ Sat Nov 14, 2009 10:35 pm ]
Post subject:  Re: Acceleration Variable?

I tried using "mass*Vel.Magniude" but the number was to high. Is there any way to measure force without acceleration?

Author:  Grif [ Sat Nov 14, 2009 10:42 pm ]
Post subject:  Re: Acceleration Variable?

That's the problem; you're not trying to measure force, you're trying to measure kinetic energy, which is another thing entirely. At least, from what I'm guessing about your purpose.

Author:  CaveCricket48 [ Sat Nov 14, 2009 11:01 pm ]
Post subject:  Re: Acceleration Variable?

I'm trying to make a "rope."

Author:  411570N3 [ Sun Nov 15, 2009 1:11 am ]
Post subject:  Re: Acceleration Variable?

I'm not really sure that the units matter as long as they're in distance/time^2. Granted, you'd need to do some scaling, but pixels/simupdates^2 should be fine.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/