RaceXtreme Posted June 4, 2011 Share Posted June 4, 2011 Hey guys Im RaceXtreme and i script a long time ago, but now im stuck in a part of it (mainly maths and physical one). And i want to make 3 questions for you guys... and there we go: 1 - Its possible to brake some gravity physics in MTA? > Follow the situation below with the pic The black square is my car. The green arrow is the gravity of the game. The red/yellow arrow means that the car is running like a speed of 0.6 (speed of the game). The brown line is the ground (some carshades (ID: 3458 ) can be as exemple) and the 20 number means that the objects are 20m of the water. The blue line obviously means the water that is 0m high. And the situation is that: My car is running forward and the carshades objets are rotating in the y axis and finaly my car gets upsidedown. Obviously it will fell to the water. !! But the question is... can i avoid that this happen without affecting the gravity element? It has some functions that can support this? 2 - Its possible to rotate a bike in 360º while playing? > Follow the picture for reference (: Ok, the black rectangle is my bike/motobike. The red/yellow means that my bike/motobike is running. And the brown line is the ground, 0 in the y position. The 2º situation is that: My bike is running and quickly it jump in a ramp. I press the "down" button and my bike starts to spin. And theres is my problem! My bike just stop to spin in the ~90º degrees and it spin in a way that back to ~0º rotation. !! So, its possible to build a script that makes that the motobike rotate the hole 360º in both directions (forward and backward)? 3 - What About using trigonometry to help to calculate things? > Picture below... x) Follow my situation... -Why we use those sin, cos, tg, rad and those maths in scripting? To calculate the given values to find the answer! -But how i can use that? Just start to learn math. -I learned what is those terms but i still dont know how to use it and when is necessary to apply it. Stuck here. !!So there is a way to learn with some tutorials and exemples? If yes, where i can find those stuff? If no, what to do now? Yeea guys... to much things to read... thanks to read this big text (of course if you read ) and if you could answer my questions i will be verry grateful! Regards, RaceXtreme. P.s: Sorry for some english mistakes . If you dont understand me, ask please! Link to comment
Dark Dragon Posted June 4, 2011 Share Posted June 4, 2011 for 1 and 2 these resources might help you: https://community.multitheftauto.com/index.php?p= ... ils&id=329 https://community.multitheftauto.com/index.php?p= ... ils&id=430 for 3 i have no clue what you're asking for Link to comment
RaceXtreme Posted June 4, 2011 Author Share Posted June 4, 2011 Oh thanks you man (you're too fast!) x) There's 2 resources that can get me a nice idea (why i didnt thought that was so "simple") Ok about the 3º question... Im trying to understand how you (and more programmers) use the trigonometric stuff to calculate things to get values. Like: "x = ( math.sin(60) + math.cos(40) )/360" (im inventing this thing okey? ) And you just get the correct value of the X position for a object based in main values. -So...? Then im trying to leran how to think in that way and when i will need use this in my scripts! -What I want? To learn how to make those scripts and get notice when i will need to make those type of calculation. Theres tutorials in the internet to help me with this? if no, what i should do? That its Thx man for the attention. Link to comment
Discord Moderators Zango Posted June 5, 2011 Discord Moderators Share Posted June 5, 2011 There are plenty of tutorials on the Internet that teaches you this. It's hard to use it in scripting if you don't understand them, or at least know how to use them beforehand. Link to comment
RaceXtreme Posted June 5, 2011 Author Share Posted June 5, 2011 Yea, it really has some good tutoriais that can show me good basics of it ( i was looking for since March ). But can you just show me a idea how do you notice that you will have to use those math stuff in your scripts? Link to comment
karlis Posted June 5, 2011 Share Posted June 5, 2011 its hard to answer you about the maths, if we don't know what you exactly want, theres 1000different uses for maths. Link to comment
SDK Posted June 5, 2011 Share Posted June 5, 2011 Like karlis said, that's hard to answer. Some scripts can be made with or without maths and have the same effect. You will probably need them most if you want to calculate something complex with angles and vectors (eg. positions, rotations, velocity and gravity vectors) but it can also be usefull in GUI's. Link to comment
RaceXtreme Posted June 6, 2011 Author Share Posted June 6, 2011 Oh right you guys is saying exactly what i want Ok karlis and SDK can you give me just a simple exemple using math (can be trigonometry ;D that is more hard for me) in position element? Then i you guys can help me in some points... Link to comment
karlis Posted June 6, 2011 Share Posted June 6, 2011 umm, position? simplest thing i could think of is to mirror object 2pos against obj1 local x1,y1,z1=getElementPosition(theObj1) local x2,y2,z2=getElementPosition(theObj2) setElementPosition(theObj2,x1-(x2-x1),y1-(y2-y1),z1-(z2-z1)) Link to comment
RaceXtreme Posted June 7, 2011 Author Share Posted June 7, 2011 Great Karlis ^^! Simplest code is easier to discuss about (: umm, i understood what is script here You made an mathematical expression to calculate the positions of 2 objects that result that the 2nd object gets mirror against the 1st one. Ok... now lets give some values and see the script works x1 = 10, y1 = 20, z1 = 5 >> object 1 Position! x2 = 30, y2 = 10, z2 = 15 >> object 2 Position! local x1,y1,z1 = getElementPosition(theObj1) -- get the position of the frist one local x2,y2,z2 = getElementPosition(theObj2) -- get the postion of the second one setElementPosition( theObj2,x1-(x2-x1),y1-(y2-y1),z1-(z2-z1) ) -- Now lets make the calculation below! -> 1 ( theObj2, 10-(30-10),20-(10-20),5-(15-5) ) -> 2 ( theObj2, 10-(20),20-(-10),5-(10) ) -> 3 ( theObj2, -10,30,-5 ) -->> Ok... first doubt is: Why it given 30 as value? : D. It shouldn't be -20? Something wrong with mine math? Edit: I tested on MTA! it gave the same values ( -10,30,-5 ) Link to comment
Callum Posted June 7, 2011 Share Posted June 7, 2011 To answer question 3, getDistanceBetweenPoints2D uses triginometry to calculate the distance between 2 vectors on the map. Link to comment
karlis Posted June 7, 2011 Share Posted June 7, 2011 x1 = 10, y1 = 20, z1 = 5 >> object 1 Position! x2 = 30, y2 = 10, z2 = 15 >> object 2 Position! -> 3 ( theObj2, -10,30,-5 ) -->> Ok... first doubt is: Why it given 30 as value? : D. It shouldn't be -20? Something wrong with mine math? Edit: I tested on MTA! it gave the same values ( -10,30,-5 ) no, it is alright that it gives 30, cuz we are mirroring OBJ2 against OBJ1, not opposite. heres how getDistanceBetweenPoints3D & 2D works: distance=( (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 ) ^ 0.5 --^0.5 works same as squareroot, and if its 2D, not 3D, remove the Z1 & Z2 part Link to comment
nowofresh Posted June 7, 2011 Share Posted June 7, 2011 My expressions with 2 years scripting in mta: -70% my time i was fixing mta engine and functions, because currently mta funcs. are bugged, cursor dosent work sometimes, every func. in time dosent detect object without collis. - i was trying ( lineOfSight, onEkementClick, onCursorClick - +/- ) -About 1 year I write new physics for objects, and ? VPS for 4 000$, 10 players and 60% using processor. -I wrote multi therds for engine and... not better. -Samp and 450 players ~~ ok... mta with 120 = traggedy -Mta and optimization is like 2+2 and 2-2... -Mta sync - 2# traggedy... Mta developers, u thinks if We cant do the best severs around the world, DO FUCK OPTIMIZATION, multi thirds etc. Vps for 3 000$ , 10 players and lags? ... Vps for 400$ + samp + 400 players and NO LAGS Link to comment
karlis Posted June 7, 2011 Share Posted June 7, 2011 its not MTA, but how you write it. plus MTA has 5times better sync then samp. Link to comment
Castillo Posted June 7, 2011 Share Posted June 7, 2011 Very long time ago when I couldn't play MTA I played SAMP for about a month, and I opened my own server, well, my ping was 65000 or something like that, then I switched to MTA and my ping got to 280-300 max. Link to comment
RaceXtreme Posted June 9, 2011 Author Share Posted June 9, 2011 (edited) MTA is the best GTA multiplayer ever ( i play since MTA Race 0.5 ) Ok guys, idk why nowofresh wrote that in his post.... but anyway lets back to our sense (: About the frist math script... setElementPosition( theObj2,x1-(x2-x1),y1-(y2-y1),z1-(z2-z1) ) >to make the object mirror to another you use this mathematical expression "a1-(a2-a1)" where's a1 and a2 are the position values. > How did you tought in that expression? Its geometry default one? Or did you "invite" it? thx ;D P.S: If you guys (Karlis, Solidsnake14 and others guys that are reading the topic) dosent understand my question dont forget to ASK me!!! (: Edited June 9, 2011 by Guest Link to comment
karlis Posted June 9, 2011 Share Posted June 9, 2011 i just logically found out the expression when i needed it. Link to comment
RaceXtreme Posted June 9, 2011 Author Share Posted June 9, 2011 Oh karlis, you tooo fast ;D So, where you found those expressions? You've learned in school? (: Link to comment
karlis Posted June 9, 2011 Share Posted June 9, 2011 i just logically found out the expression when i needed it. Link to comment
RaceXtreme Posted June 10, 2011 Author Share Posted June 10, 2011 Oh sorry, i didnt read carefuly x) Ok ok ^^ Lets see the 2nd expression: distance=( (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 ) ^ 0.5 --^0.5 works same as squareroot, and if its 2D, not 3D, remove the Z1 & Z2 part > ook lets make an exemple... We want to get the distance between 2 points 2D, where the 1st one is a cube object thats is x1=20,y1=60 and the 2nd one is x2=50,y2=10. distance=( (x1-x2)^2 + (y1-y2)^2 ) -- this i understood (x1-x2 > thats get the distance between those 2 objets) but the "^2" i didnt. Why we use the squareroot if we already get the this distance between those 2 objects? (: distance=( (20-50)^2 + (60-10)^2 ) -- lets test it : D distance=( (-30)^2 + (50)^2 ) distance=( (-30)*(-30) + (50)*(50) ) distance=( (900) + (2500) ) distance=( 3400 ) -- correct? (: >Now lets do it! 3400*0.5 = 1700! --Hmmm... 0,5 is to reduce this value... 0,5 is mainly for what? --1700 is the distance between those points... Its possible to see this distance is meters to make things easier like in map editor? Thx in advance Link to comment
SDK Posted June 10, 2011 Share Posted June 10, 2011 Wrong, you did *0.5. It's ^0.5. => http://mathbin.net/63264 http://en.wikipedia.org/wiki/Pythagorea ... te_systems Link to comment
karlis Posted June 10, 2011 Share Posted June 10, 2011 the sum of two short ledges distance squares equals to the sum of biggest ledge square, if triangle has a 1 90degree corner, thats Pythagoras(dunno how it spells right) theorem. in this case we consider the short ledges to be the x and y offset, and the long ledge to be the distance between points. Link to comment
NeXTreme Posted June 10, 2011 Share Posted June 10, 2011 About your 3rd question.... Sine Function: sin(θ) = Opposite / Hypotenuse Cosine Function: cos(θ) = Adjacent / Hypotenuse Tangent Function: tan(θ) = Opposite / Adjacent An example: Use the sine function to find "d" We know * The angle the cable makes with the seabed is 39° * The cable's length is 30 m. And we want to know "d" (the distance down). Start with: sin 39° = opposite/hypotenuse = d/30 Swap Sides: d/30 = sin 39° Use a calculator to find sin 39°: d/30 = 0.6293… Multiply both sides by 30: d = 0.6293… x 30 = 18.88 to 2 decimal places. (obviously you could just use the math.sin function here, and then multiply by 30) The depth "d" is 18.88 m Take a look at this website, it has some more explanations on this (it's also where I got this nice explanation and pictures from): http://www.mathsisfun.com/sine-cosine-tangent.html It has more explanations on how to use sine, cosine and tangent math functions. A good example of using these functions is in a loop generator, where you need to find the angles at which to place the pieces of the track. Also another link: http://www.mathsisfun.com/algebra/trigo ... index.html You can find virtually everything about trigonometry here. Good luck Link to comment
RaceXtreme Posted June 10, 2011 Author Share Posted June 10, 2011 Off: Oh NeXTreme i relember you from FFS Racing Server, brother (if im not wrong, of course ) -- A lot thx guys, now i just got the idea that i didnt get a long time ago ( I was trying to see how this 90 degree triangle works on a game ) Huum, now just some another questions The squareroot works like (x)^0.5 because 0.5 is the half of the whole number? Hmm, to calculate the distance between points 3D we use: distance=( (x1-x2)^2 + (y1-y2)^2 + (z1+z2) )^0.5 ) -- but the 3º element is what in the Pythagoras theorem? ( a²+b²+c² ) -- Its the "a" one? ( x = a²+b²+c² ) and what is this x? About NeXTreme said, "A good example of using these functions is in a loop generator". I opend the code and get a doubt: -- its correct my analysis? newx = orx + radi*math.sin(radians)*math.cos(rota)+(offset/2)*math.cos(radians/(2*loops))*-math.sin(rota) --newx = is the sum of the original x with the calculation of one side of a 90 degree triangle? (; Thanks in advance (: Link to comment
karlis Posted June 11, 2011 Share Posted June 11, 2011 correction: distance=( (x1-x2)^2 + (y1-y2)^2 + (z1+z2)^2 )^0.5 ) also that the 3rd z value can be added i figured logically(although im sure its documented somewhere too) imagine, you get the hypotenuse of the x and y, so u get 2D distance.then you get height(Z value), and make the distance in 2D to be one of the short triangle edge, and height the second. obliviously you will get 3D distance as result in repeated Pythagoras theorem. so this is what we came up with: distance=( (((x1-x2)^2 + (y1-y2)^2)^0.5)^2 + (z1+z2)^2 )^0.5 ) now we can shorten it: distance=( (x1-x2)^2 + (y1-y2)^2 + (z1+z2)^2 )^0.5 ) 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