## Recommended Posts

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. 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.

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. 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.

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

Useless page. I know functions, i dunno WHAT are sin and cos. 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() ) )

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)

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

Useless ? Wow. I shows EXACTLY how they work with the examples. My god...

well someone who doesn't know trig can find it useless

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.

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

Trig isn't really the best way to understand what exactly sin and cos are.

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

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