View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:47 am



Reply to topic  [ 13 posts ] 
 Acceleration Variable? 
Author Message
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Acceleration Variable?
Is there a Lua variable for an object's acceleration?


Sat Nov 14, 2009 7:01 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Acceleration Variable?
Well, before we go any further, why do you need that?


Sat Nov 14, 2009 8:45 pm
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Acceleration Variable?
I'm trying to make a "rope."


Sat Nov 14, 2009 11:01 pm
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post 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
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 13 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.053s | 13 Queries | GZIP : Off ]