Jump to content

Help me with some physical and math questions!


Recommended Posts

Hey guys :P

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: xD

1 - Its possible to brake some gravity physics in MTA?

> Follow the situation below with the pic :)

img0z.png

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 (:

img1k.png

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)

img2w.png

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! :D

Regards,

RaceXtreme.

P.s: Sorry for some english mistakes xD.

If you dont understand me, ask please!

Link to comment

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

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

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

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

Great Karlis ^^! Simplest code is easier to discuss about (:

umm, i understood what is script here :D 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 :D

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 ) :wink:

Link to comment

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 ) :wink:

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

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

MTA is the best GTA multiplayer ever ( i play since MTA Race 0.5 :D )

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 by Guest
Link to comment

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 :D

Link to comment

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

About your 3rd question....

adjacent-opposite-hypotenuse.gif

Sine Function: sin(θ) = Opposite / Hypotenuse

Cosine Function: cos(θ) = Adjacent / Hypotenuse

Tangent Function: tan(θ) = Opposite / Adjacent

An example:

trig-2example2.gif

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 :D

Link to comment

Off: Oh NeXTreme i relember you from FFS Racing Server, brother :D (if im not wrong, of course :D)

--

A lot thx guys, now i just got the idea that i didnt get a long time ago :D ( I was trying to see how this 90 degree triangle works on a game )

Huum, now just some another questions xD

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

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

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.
×
×
  • Create New...