## 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. #### Share this post

##### Link to post

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.

#### Share this post

##### Link to post

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. #### Share this post

##### Link to post

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.

#### Share this post

##### Link to post

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

#### Share this post

##### Link to post

Useless page. I know functions, i dunno WHAT are sin and cos. #### Share this post

##### Link to post
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() ) )

#### Share this post

##### Link to post
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)

#### Share this post

##### Link to post

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

#### Share this post

##### Link to post
Useless ? Wow. I shows EXACTLY how they work with the examples. My god...

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

#### Share this post

##### Link to post

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.

#### Share this post

##### Link to post
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

#### Share this post

##### Link to post

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

#### Share this post

##### Link to post

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

#### Share this post

##### Link to post

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

## 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 account

## Sign in

Already have an account? Sign in here.

Sign In Now

• ### Recently Browsing   0 members

No registered users viewing this page.