View unanswered posts | View active topics It is currently Wed Jan 08, 2025 10:41 pm



Reply to topic  [ 11 posts ] 
 Lua Terms 
Author Message
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Lua Terms
Just wondering what these terms mean (not what tangent means, what the variables mean). Like what the forumla, i guess, is stating.

Code:
math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2))
            

actor.Vel.Y = actor.Vel.Y - (100 / diff * math.sin(ang))
            

actor.Vel.X = actor.Vel.X - (100 / diff * math.cos(ang))



Thanks a lot! :)


Sun Jun 07, 2009 1:49 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua Terms
http://lua-users.org/wiki/MathLibraryTutorial


Sun Jun 07, 2009 1:51 am
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Lua Terms
So like tangent and sine and cosine......are all trig stuff with triangles, so when you use those functions, does it create an imaginary triangle? I'm just confused as to how its actaully used. I get how to find them and such, but im confused as to how they are used in CC.


Sun Jun 07, 2009 2:42 am
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: Lua Terms
They're mathematical functions.
You can use them to find the direction of something in degrees from their relative co-ordinates.
You can also use them to make snazzy curve lines.


Sun Jun 07, 2009 5:03 am
Profile WWW
User avatar

Joined: Sun May 11, 2008 12:50 pm
Posts: 899
Reply with quote
Post Re: Lua Terms
Code:
math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2))

Gets the distance between two actors, I think. (Pythagorean theorem thingamabob)

Can't help you with the other stuff, I haven't learned trig yet. :(


Sun Jun 07, 2009 3:02 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua Terms
Roon3 wrote:
Code:
math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2))

Gets the distance between two actors, I think. (Pythagorean theorem thingamabob)

Can't help you with the other stuff, I haven't learned trig yet. :(


You're exactly right so don't feel bad.

math.sqrt (so the entire rest of the statement is the square root) and then math.pow (exponent/power) of the x distance between the two actors squared, then the same for the y distance.


Sun Jun 07, 2009 5:43 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Lua Terms
Yeah, so its obviously the distance formula,

{[(square root of(((x2-x1)^2) + (y2-y1)^2)] or like [sqaure root of the change in x sqyared plus the change in y squared]}

just in lua terms between point a and point b. I get that part. Just dont get how like piipu gets his vortex gun to work like it does.


Last edited by Mind on Sun Jun 07, 2009 7:25 pm, edited 1 time in total.



Sun Jun 07, 2009 7:22 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua Terms
What's diff defined as? Let me guess here: the distance between the target and the vortex.

It's the same thing as my teleporter code; just in a different way.


Sun Jun 07, 2009 7:24 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Lua Terms
Code:
function Update(self)
         local diff = math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2)) <-- distance between vortex and actor i know.
          if diff < 30 then  <---- if the distance between the two is less than 30 then
            diff = 30 <--- the distance is 30
            actor.Health = 0  <--- actor hp is 0
         end
         if (diff < 400) and actor.PinStrength == 0 then  <---- obvious
            local diffx = actor.Pos.X - self.Pos.X  <-----the lengthdir_x
            local diffy = actor.Pos.Y - self.Pos.Y <-----the lengthdir_x
             local ang = math.atan2(diffy,diffx)  *** **why is it finding the opposite tangent of the two sides? 
            actor.Vel.Y = actor.Vel.Y - (100 / diff * math.sin(ang))  <----the y velocity is 100 divided by the distance between the two times the sin of the second tangent of the two sides of the triangle (lengthdir_x,lengthdir_y)
            actor.Vel.X = actor.Vel.X - (100 / diff * math.cos(ang))  same cept x
         end



      end


I just dont get what the starred areas do, and correct me if im wrong with the others :)


Sun Jun 07, 2009 7:31 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua Terms
The diff is the difference between the two positions. math.atan2 determines the root angle of a triangle based on the diffy and diffx.

So what the entire script does is this:

if an actor is within a distance of 400 pixels
if the actor is within 30 pixels of the vortex, kill them

if the difference is less than 400 and the actor is not pinned
find the opposite and adjacent of a triangle
find the root angle of the same triangle
then set the velocity of the actor to 100 divided by the hypotenuse of that triangle, resulting in an inward suction effect


Sun Jun 07, 2009 7:37 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Lua Terms
Grif wrote:
The diff is the difference between the two positions. math.atan2 determines the root angle of a triangle based on the diffy and diffx.

So what the entire script does is this:

if an actor is within a distance of 400 pixels
if the actor is within 30 pixels of the vortex, kill them

if the difference is less than 400 and the actor is not pinned
find the opposite and adjacent of a triangle
find the root angle of the same triangle
then set the velocity of the actor to 100 divided by the hypotenuse of that triangle, resulting in an inward suction effect


Oh..... ok. Im trying to make something along the lines of that, cept its not. Ill post if i can't get it :3


Sun Jun 07, 2009 7:47 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.054s | 15 Queries | GZIP : Off ]