Data Realms Fan Forums
http://45.55.195.193/

Lua Terms
http://45.55.195.193/viewtopic.php?f=73&t=15229
Page 1 of 1

Author:  Mind [ Sun Jun 07, 2009 1:49 am ]
Post subject:  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! :)

Author:  Grif [ Sun Jun 07, 2009 1:51 am ]
Post subject:  Re: Lua Terms

http://lua-users.org/wiki/MathLibraryTutorial

Author:  Mind [ Sun Jun 07, 2009 2:42 am ]
Post subject:  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.

Author:  411570N3 [ Sun Jun 07, 2009 5:03 am ]
Post subject:  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.

Author:  Roon3 [ Sun Jun 07, 2009 3:02 pm ]
Post subject:  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. :(

Author:  Grif [ Sun Jun 07, 2009 5:43 pm ]
Post subject:  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.

Author:  Mind [ Sun Jun 07, 2009 7:22 pm ]
Post subject:  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.

Author:  Grif [ Sun Jun 07, 2009 7:24 pm ]
Post subject:  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.

Author:  Mind [ Sun Jun 07, 2009 7:31 pm ]
Post subject:  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 :)

Author:  Grif [ Sun Jun 07, 2009 7:37 pm ]
Post subject:  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

Author:  Mind [ Sun Jun 07, 2009 7:47 pm ]
Post subject:  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

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