I wouldn’t call myself a beginner because I know quite a lot about scripting Lua in Roblox, but there’s one thing I can never seem to understand equations. I don’t mean “how do I make equations”. I mean "why does X * Y = angular speed or something like that. Is this something I’ll learn later on in school? Or am I just being stupid? I’m not sure if that made sense but comment anything you think will be helpful.
Because speed is how far you travel in a certain amount of time.
It’s all connected, so you can calculate one of the 3 values if you know the other 2.
speed = distance / time
10 km/h = 20km / 2h
distance = speed * time
50m = 10m/s * 5s
time = distance / speed
2h = 5mi / 10mi/h
(and just replace distance with angle for angular speed)
This is something you learn about in school.
Ok well i guess thats the reason why im not even done with middle school yet. Im talking about more complex questions though, like figuring out direction.
What exactly do you want to achieve? Are you trying to make a parabola or do you just want a part to move forward or side to side? You should look into using the RunService and hook events up to it and mess around with moving a parts CFrame. For example, if you wanted to move a part every frame you could do something like this:
local speed = 10
runService.Heartbeat:Connect(function(delta)
part.CFrame = part.CFrame * CFrame.new(part.CFrame.LookVector * speed * delta)
end)
I hope my post helped a little bit.
With right angle triangles everything is also connected, there are just more connections…
Sides to sides
With a Vector2.new(3,4)
you get this:
- Green is a = X = 3
- Blue is b = Y = 4
- Red is c (calculated below)
a2 + b2 = c2
32 + 42 = 25
sqrt(25) = sqrt(c2) = c = 5
(:Magnitude()
does this)
And so
c2 - b2 = a2
and
c2 - a2 = b2
Sides to angles
Now for angles it gets a little more complex
If you want to calculate ∠CAB (the purple dotted line) using a and b
then
- AC = c = hypotenuse (always the longest line)
- AB = a = adjacent (the line connected to your corner)
- BC = b = opposite (the line not connected to your corner)
arctan(opposite / adjacent) = ∠CAB
arctan(4 / 3) = ∠CAB
arctan(1.3333…) = ∠CAB
0.92729… rad = 53.1301…°
(you can use math.atan(b/a)
here to get a value from -90 to 90 degrees (in radians), but if you use math.atan2(b, a)
you get a value from -180 to 180 degrees instead (also in radians) (it does some extra checks or something))
To calculate ∠BCA it’s the same thing but from the perspective of C
(so then AB is the opposite and BC is the adjacent side)
And we already know that ∠ABC is 90° because this is a right angle triangle
Angles to angles
The angles of triangles always add up to 180° (not only on right angle triangles) so it’s easy to convert between them:
∠ABC + ∠BCA + ∠CAB = 180°
180° - ∠ABC - ∠CAB = ∠BCA
90° - ∠CAB = ∠BCA
90° - 53.1301… = 36.8699…
180° - ∠ABC - ∠BCA = ∠CAB
180° - ∠BCA - ∠CAB = ∠ABC (= 90°)
Angles with side to sides
You can’t use only angles to convert to sides, because a triangle that is twice as big still has the same angles.
sin(∠BCA) = opposite / hypotenuse
sin(∠BCA) * hypotenuse = opposite
cos(∠BCA) = adjacent / hypotenuse
cos(∠BCA) * hypotenuse = adjacent
tan(∠BCA) = opposite / adjacent
tan(∠BCA) * adjacent = opposite
Sin, cos and tan
Sin, cos and tan are also connected, but I doubt you’ll ever need these conversions.
z can be any number (not NaN and probably not infinity either)
sin(z) = cos(z + 90°)
cos(z) = sin(z - 90°)
tan(z) = sin(z) / cos(z)
There are more conversions you can come up with, but these are the only ones you really need to solve for an angle or a side when you know 2.
Here is the desmos graph I made for the visuals, so you can play around with it or something.
(I made some of the points dragable)
If you have specific questions about equations, or have a problem you want to solve but don’t know the equation of how to solve it, just google it. There are plenty of good tutorials and explanations out there! They may not explain exactly how to implement them on Roblox, but if you try something out in a script and it isn’t working you can always ask around here.