generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

[ Content Deleted ]

Previous Thread :: Next Thread 
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
18 Apr 2012 03:49 PM
How would you do
TAN^(-1) (I.E. the opposite of tangent.) in lua.

All I can find in the math functions thing is math.tan()

http://wiki.roblox.com/index.php/Function_Dump/Mathematical_Functions#math.tanh.28x.29

Report Abuse
yacker3000 is not online. yacker3000
Joined: 22 Nov 2008
Total Posts: 259
18 Apr 2012 03:52 PM
If I understood your question correctly, math.atan2(y, x) should work.

http://wiki.roblox.com/index.php/Function_Dump/Mathematical_Functions#math.atan.28x.29
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
18 Apr 2012 04:02 PM
[ Content Deleted ]
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
18 Apr 2012 04:10 PM
Can you tell me why this compass script is totally off? I think it's the radians to degrees. Here's the math code:

local FocusPos = Workspace.CurrentCamera.Focus.p
local CamPos = Workspace.CurrentCamera.CoordinateFrame.p
local DegreesPoint = math.atan((CamPos.X-FocusPos.X)/(CamPos.Y-FocusPos.Y))*(180/math.pi) --Degrees in which the player is staring at.
local ThisRot = LastRot + (LastRot - DegreesPoint)*Delta/SmoothnessFact
LastRot = ThisRot
print("Last rotation: "..LastRot)
print("DegreesPoint: (Degrees to which the player is staring) "..DegreesPoint)
print("ActualRotation: (With smoothness build in) "..ThisRot)

CompassContainer.North.Position = GetPos(ThisRot)


Delta = wait(0.05)
Report Abuse
HotThoth is not online. HotThoth
Forum Moderator
Joined: 24 Aug 2010
Total Posts: 1176
18 Apr 2012 04:13 PM
If you draw a line from the origin to a point on a circle, this line has a slope and it also has an angle it makes with the positive x axis. Arctangent(slope) gives you the angle which makes that slope.

....../.
...../..
..../...
-------> +x
../....
./.....
/......


^ In the upper-right hand corner, the slope is like 2 and the angle is like 60 degrees. But in the lower-left corner, the slope is still 2, but the angle is like 255 degrees. Arctangent has no way of telling the difference, so if you actually give it rise and run (y and x) instead of slope (y/x), then arctan2 can tell you whether it's 60 degrees or 255 degrees. Arctangent by itself will just always give you 60-degrees.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
18 Apr 2012 04:20 PM
So instead of:


local DegreesPoint = math.atan((CamPos.X-FocusPos.X)/(CamPos.Y-FocusPos.Y))*(180/math.pi) --Degrees in which the player is staring at.


to get the degrees, I should do..


local DegreesPoint = math.atan2(CamPos.X-FocusPos.X), (CamPos.Y-FocusPos.Y))*(180/math.pi)


But I'm still not sure why my coordinates are randomly changing, and stuff.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
18 Apr 2012 04:27 PM
Might be because I'm using Y instead of Z...

-___-


DegreesPoint = math.atan2((CamPos.X-FocusPos.X), (CamPos.Z-FocusPos.Z))*(180/math.pi)

Fixed it? I now get a range of -180 to 180...


Also, does this line seem kind of... bad....


local ThisRot = LastRot + (LastRot - DegreesPoint)*Delta/SmoothnessFact


Oysi provided it, but... :/
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
18 Apr 2012 04:30 PM
Wait wait wait. The arguments are ALSO in radians... :/


local DegreesPoint = math.atan2(math.rad(CamPos.X-FocusPos.X), math.rad(CamPos.Z-FocusPos.Z))*(180/math.pi)

There we go.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
18 Apr 2012 04:40 PM
Nevermind. I'm so confused.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
18 Apr 2012 04:52 PM
Nevermind. I fixed it.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image