Author |
Message |
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Acceleration Variable?
Is there a Lua variable for an object's acceleration?
|
Sat Nov 14, 2009 7:01 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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.
|
Sat Nov 14, 2009 8:26 pm |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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?
|
Sat Nov 14, 2009 8:43 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Acceleration Variable?
Well, before we go any further, why do you need that?
|
Sat Nov 14, 2009 8:45 pm |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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".
|
Sat Nov 14, 2009 9:04 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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.
|
Sat Nov 14, 2009 9:42 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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.
|
Sat Nov 14, 2009 10:00 pm |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
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.
Last edited by CrazyMLC on Sat Nov 14, 2009 10:08 pm, edited 4 times in total.
|
Sat Nov 14, 2009 10:00 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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.
|
Sat Nov 14, 2009 10:03 pm |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Acceleration Variable?
I tried using "mass*Vel.Magniude" but the number was to high. Is there any way to measure force without acceleration?
|
Sat Nov 14, 2009 10:35 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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.
|
Sat Nov 14, 2009 10:42 pm |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Acceleration Variable?
I'm trying to make a "rope."
|
Sat Nov 14, 2009 11:01 pm |
|
|
411570N3
Joined: Wed Jan 07, 2009 10:26 am Posts: 4074 Location: That quaint little British colony down south
|
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.
|
Sun Nov 15, 2009 1:11 am |
|
|
|