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 |
|
|
|
| 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
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
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
|
  |
 |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 18 Apr 2012 04:40 PM |
| Nevermind. I'm so confused. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
| |
|