Atti Posted February 15, 2008 Share Posted February 15, 2008 These math functions are used to get a position in front of a player, by getting his rotation, i.e. for spawning ramps. Now i need them in my script, but i don't like using things that i don't understand, so can you simply explcate me how these work? Or at least what values should i pass to the functions. Thx a lot if you can do it, i'm really a n00b in maths. Link to comment
Ace_Gambit Posted February 15, 2008 Share Posted February 15, 2008 Search for math.sin and you'll find the answer. Someone already posted a code-snippet for spawning objects with the sin/cos function. And it doesn't require any mathematical knowledge to understand it. Link to comment
Atti Posted February 15, 2008 Author Share Posted February 15, 2008 I've got no problems copying that code. I just would like to understand why an x coord reduced by the sin of the radius of the Z rotation is placed in fornt of the player. Link to comment
tma Posted February 15, 2008 Share Posted February 15, 2008 It's basic trig - how to rotate a point round any other. In the ramp examples the origin is set to the vehicle/player and the remote object becomes the "point" to be rotated. Link to comment
Woovie Posted February 15, 2008 Share Posted February 15, 2008 Handy page. http://lua-users.org/wiki/MathLibraryTutorial math.cos , math.sin - > = math.cos(math.pi / 4) 0.70710678118655 > = math.sin(0.123) 0.12269009002432 Link to comment
Atti Posted February 15, 2008 Author Share Posted February 15, 2008 Useless page. I know functions, i dunno WHAT are sin and cos. Link to comment
norby89 Posted February 15, 2008 Share Posted February 15, 2008 Useless page. I know functions, i dunno WHAT are sin and cos. you might wanna ask your maths teacher or visit this site http://en.wikipedia.org/wiki/Trigonometry and these sites are awesome to help you visualize how the trigonometric circle works http://www.senocular.com/flash/source.php?id=0.114 http://www.edumedia-sciences.com/a348_l ... ircle.html keep in mind that Lua uses radians for math.cos, math.sin etc and MTA uses degrees, so for example if you get a player's rotation you need to convert it to radians when using these functions like this: math.cos ( math.rad ( getPlayerRotation ( getLocalPlayer() ) ) Link to comment
Jumba' Posted February 15, 2008 Share Posted February 15, 2008 Handy page.http://lua-users.org/wiki/MathLibraryTutorial math.cos , math.sin - > = math.cos(math.pi / 4) 0.70710678118655 > = math.sin(0.123) 0.12269009002432 Oh, but Like normally you have sin and sin-1 (inversed) How do you do that in lua? (the sin-1 part) Link to comment
Woovie Posted February 15, 2008 Share Posted February 15, 2008 Useless ? Wow. I shows EXACTLY how they work with the examples. My god... And inverses math.acos , math.asin Return the inverse cosine and sine of the given value. > = math.acos(1) 0 > = math.acos(0) 1.5707963267949 > = math.asin(0) 0 > = math.asin(1) 1.5707963267949 Link to comment
norby89 Posted February 15, 2008 Share Posted February 15, 2008 Useless ? Wow. I shows EXACTLY how they work with the examples. My god... well someone who doesn't know trig can find it useless Link to comment
Woovie Posted February 15, 2008 Share Posted February 15, 2008 You can learn how it works. I don't know trig but I can understand it and I learned from using LUA. Just make some simple math functions that output the answer to chat to learn them.. It is fairly simple. Link to comment
norby89 Posted February 15, 2008 Share Posted February 15, 2008 You can learn how it works. I don't know trig but I can understand it and I learned from using LUA. Just make some simple math functions that output the answer to chat to learn them.. It is fairly simple. dunno about you but if I didn't know about the basics of trig I'd have no idea what sine and cosine are, I'd say it outputs random numbers and probably would ask for help like Atti did Lua doesn't teach you math Link to comment
Twig Posted February 15, 2008 Share Posted February 15, 2008 Trig isn't really the best way to understand what exactly sin and cos are. Link to comment
Jumba' Posted February 15, 2008 Share Posted February 15, 2008 I get sin and cos extensively at school and I work with them (at school) regularly, but I cant really visualize what happens when you do it on the x,y,z coords. But I guess i'd just have to experiment and see Link to comment
darkdreamingdan Posted February 15, 2008 Share Posted February 15, 2008 You dont do it with coordinates, its relevant to the rotation. This graph of sin and cos might make it clearer(its in degrees not radians): http://www.mathsrevision.net/alevel/pure/sincostan.gif Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now