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 » Scripters
Home Search
 

[ Content Deleted ]

Previous Thread :: Next Thread 
IAmNotWise is not online. IAmNotWise
Joined: 28 Jul 2011
Total Posts: 1418
05 Feb 2012 12:33 PM
[ Content Deleted ]
Report Abuse
Shobobo99 is not online. Shobobo99
Joined: 30 Dec 2008
Total Posts: 5754
05 Feb 2012 12:54 PM
The tangent of two sides is opposite side over adjacent side, and assuming x is the adjacent side, it would be:

math.atan(y/x)
Report Abuse
IAmNotWise is not online. IAmNotWise
Joined: 28 Jul 2011
Total Posts: 1418
05 Feb 2012 01:06 PM
[ Content Deleted ]
Report Abuse
sdfgw is not online. sdfgw
Top 50 Poster
Joined: 08 Jan 2009
Total Posts: 41681
05 Feb 2012 02:40 PM
Sounds like you're looking for

math.atan2(x, y)
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
05 Feb 2012 02:45 PM
@sdfgw is correct. `math.atan2(x, y)` does what you want.

Remember, floating point numbers are not infinitely accurate!
Report Abuse
IAmNotWise is not online. IAmNotWise
Joined: 28 Jul 2011
Total Posts: 1418
05 Feb 2012 02:52 PM
[ Content Deleted ]
Report Abuse
sdfgw is not online. sdfgw
Top 50 Poster
Joined: 08 Jan 2009
Total Posts: 41681
05 Feb 2012 02:55 PM
The fact that there's a function designed especially to solve your problem proves you're not the first person to struggle with turning a gradient back into an angle

darned quadrants
Report Abuse
Varp is not online. Varp
Joined: 18 Nov 2009
Total Posts: 5333
05 Feb 2012 03:08 PM
"math.atan2(x, y)"

The arguments are actually ordered y, x since you use math.atan as math.atan(y/x):
math.atan2(y, x)
Report Abuse
sdfgw is not online. sdfgw
Top 50 Poster
Joined: 08 Jan 2009
Total Posts: 41681
05 Feb 2012 03:13 PM
whoopsie

what varp said
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
05 Feb 2012 03:19 PM
<-- Knows nothing about an arctangent (is that right?).
<-- Knew to use that.
But what exactly does arc-tangent 2 do? How does it work?
tan(y/x) is simply opposite/adjacent (as denoted by SOHCAHTOA). Therefore, the arctan of y/x is the inverse tangent... which would give the angle. Now I understand :D
It just gets the quadrant (or just positive/negative) and changes the angle to an appropriate value.
So, math.atan(-3/-2) would return ~56 degrees. But math.atan2(-3, -2) would return ~(56 + 180) so about 236 (or ~-124).
Am I right?

But this would imply that you can get the x and y values from the slope. Didn't we have several huge discussions about getting fractions from decimals?
Report Abuse
Varp is not online. Varp
Joined: 18 Nov 2009
Total Posts: 5333
05 Feb 2012 04:03 PM
"But this would imply that you can get the x and y values from the slope. Didn't we have several huge discussions about getting fractions from decimals?"

If you only have slope, you should probably just use math.atan (since the data about which quadrant the angle is in has already been lost). You could use math.atan2(slope,1) if you wanted to though. Those discussions were about getting a ratio of two integers from a decimal - you don't need the integer requirement.
Report Abuse
naz100k1ller is not online. naz100k1ller
Joined: 22 Feb 2016
Total Posts: 41
06 Feb 2012 12:05 AM
?..
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
06 Feb 2012 12:12 AM
A better question is why you want to find the angle. Having angles isn't useful for very much in programming generally.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
06 Feb 2012 12:30 AM
^ Yes!

Lately I've been a bit frustrated on the over-(ab)use of trig functions and things kept in angle form when unit vectors and such are such a better choice.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
06 Feb 2012 12:33 AM
The funny thing is, is that usually users will note that a game has cool 'This' or "That', but the actual application of the nice scripting won't really change how much the player likes the game.

It's more of a game play thing then a Oh look, it's a AI!
Report Abuse
HotThoth is not online. HotThoth
Forum Moderator
Joined: 24 Aug 2010
Total Posts: 1176
06 Feb 2012 12:02 PM
I usually only use angles for when I'm rotating, or else when I want to see if something is within a cone [like if an enemy can "see" you, you can just test if its lookVector is within say 60 degrees from the vector from its head to you]. And for the second, using :Dot is the best way to go.
Report Abuse
HotThoth is not online. HotThoth
Forum Moderator
Joined: 24 Aug 2010
Total Posts: 1176
06 Feb 2012 12:06 PM
And yes, as hinted at earlier, those arc-functions are not defined over the entire (0, 2-pi) range. Sin(3pi/4) = sin(pi/4) = sqrt(2)/2, so what should arcsin(sqrt(2)/2) return? It can't return 3pi/4 AND pi/4. That's why with just arctan, you may need additional maths to get your final answer, but with arctan2, it's built in to the function, since you give it two parameters so it knows what quadrant you're in.
Report Abuse
IAmNotWise is not online. IAmNotWise
Joined: 28 Jul 2011
Total Posts: 1418
06 Feb 2012 08:25 PM
[ Content Deleted ]
Report Abuse
ChefSolo is not online. ChefSolo
Joined: 23 Oct 2011
Total Posts: 676
06 Feb 2012 10:56 PM
[ Content Deleted ]
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
07 Feb 2012 01:31 AM
"Those discussions were about getting a ratio of two integers from a decimal - you don't need the integer requirement."
Yes, I know. I was just referring to getting the quadrant (which is impossible D:).

I love the over-abuse of trig functions recently. It confirms that I know what I'm doing even though I never use trig. :D
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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