Maths in Scripting

Hello guys

So i have seen people using maths in scripting like multiplying and dividing body velocity, body force, sine, cos, tan. These thing are seen mainly in flying script, jetpacks etc…
I really wanna learn these things but how?
Its seems tooo complicated.

Thanks for reading

1 Like

You can refer to for all of these informations. Search up for math and you will see all of the math functions you can use.


Trig for well, triginomic functions (cosine, tangent, etc). Throw in some physics lessons for body movers. Your school will teach you this by the time you get into 6th form. Algebra is also something that is undeniably essential for programming.

If you want to learn these things now I recommend Khan Academy.


Math is extremely useful in scripting. I don’t understand sine, cosine or tangent yet but I just finished Algebra 1 and coding things is a lot simpler now.

What grade are you in? Jumping too far ahead in math can make you stressed and it’s better to just not mess with those things until you get to them.


I had learned algebra, I don’t know where to use it can u give me an example?

Here’s Roblox default math stuffs. math | Documentation - Roblox Creator Hub, extremely useful.

1 Like

my advice is to use the api references, and to think about it as much as possible, and then to explore all the possibilities with one aspect of a mathmatical function. then test if what you thought is true. if it isn’t, back to thinking. if it is, don’t use it too much becuase it will blow up anyone’s pc if it’s overused.

1 Like

For example, I had to determine if a part was a certain size, then it would damage a certain block.
I did something like this:

local y = -- thing being hit
    if 20 < x.Size.Z < 35 then
        if math.abs(y.Velocity.X) >= 2 then

I wrote it really quick and wasn’t really thinking of alternatives but it worked.

1 Like

A lot of people look at maths as something that’s inevitably difficult and complex, but it really isn’t. It’s a matter of applying your learning through the provided resources.

See, that’s what important. If you sit a test about a topic you do not know about, then you’re likely to do poorly. But if you adequately learn and practice, then you’re likely to excel.

Complicated maths will differ from person to person. No one magically remembers formulas and complex concepts from the top of their head like any casual Albert Einstein. You mentioned trigonometry and those functions, about things like “flying scripts, jetpacks.” So I’m curious to see if you can provide some code examples of trig in those cases. What are some applications for these functions. If you want to make a jetpack, you’ll need your player to fly upwards; can you draw a relation between an aspect of maths required to achieve this, or better put, can you visualize how you would plan on going about this?

I often find that not all math functions require a use-case. Use it when it’s necessary.

I suggest you look into the relevant articles about your doubts and see if you can learn something. And if you’re up for it, try to apply it! But, don’t be too hard on yourself.


Oh, well you should take a look at these.

Hope this helps, have an amazing rest of your day/night! :smile:

It’s my second year studying physics and my fifth year studying algebra, my suggestion is to try to get physics and algebra classes in your school because i personally find a lot more difficult studying online!

Like @wastemanty23 and others have said, try to get some algebra and physics classes (and geometry/trig). However, the only thing I disagree on is with self-study - everyone’s different. For myself, I find I learn the most when I’m researching things online, or reading through a book/article. And also, online there are courses on sites like edX from institutions, or other sites like Khan Academy, or great books you can order… it really just depends on your learning preferences. And I feel that you greatly limit yourself by being restricted to classes in numerous ways, though I’m sure @wastemanty23 didn’t mean to not learn elsewhere.

Online Courses

For first year algebra-based physics, this course on edX from Rice University I find to be good, or Khan Academy if you’re into it. The nice thing about this edX course is that it requires no more than algebra and some basic trig, which you could learn pretty easily from Khan Academy or elsewhere. And I wouldn’t worry about getting or certificate or good grades in it. In a way doing that takes stress off and allows you to focus on learning more.

For math, I haven’t tried any online courses myself besides Khan Academy. I’ve used it in the past, and I don’t personally find it to be the best for explanations, but for many people it works great.


For physics, the above is the free online book that’s used in the edX course. It’s nothing special, but it has simple and clear explanations and quite a number of examples. Also half of the book is about the coverage of the edX course (AP Physics 1), and it goes along quite well with it.

For mathematics, I’ve heard a lot of great things about the above, “the art of problem solving” (AoPS) books. They go from Prealgebra up to Calculus in their set of books, and seem to have good feedback from most people.

You can search online for practically anything nowadays. If you wanted to figure out how to script a projectile in Roblox using BodyMovers, then search online for “2D kinematics,” or “how projectiles work in physics,” and perhaps go in that earlier book or course I mentioned, or search around on the devforum! Near immediately I found this devforum topic, this online projectile article, and this other devforum topic.

In the end, I find that trying new things is the key to learning. And also breaking things down that’ve already been made to try to learn from them. Try to reach beyond what you’re comfortable doing; like instead of avoiding little projects that could involve complexity, like making a working drone, research a whole lot, try stuff out with code, and keep fixing!

And also, here’s a quick example. Let’s say you had two parts in the workspace and you wanted to find the direct distance between the two of them in studs. What you could do is this, using .Magnitude:

local partA = game.Workspace.partA
local partB = game.Workspace.partB

local distance = (partA.Position - partB.Position).Magnitude

However, if we wanted to really learn more in math/physics, then what we can do is “break it down” in order to learn from this. In further research, we can learn that .Magnitude is just a function that represents a the “length of a vector.” Imagining a vector like an arrow (—>), the direction is where the arrowhead is facing, while the magnitude is how long the arrow (vector) is; the length of the vector, devoid of direction (always positive). Thus, when we subtract the Vector3 positional values of partA and partB, we’re really creating a sort of Vector3 “arrow” pointing from one of the parts to the other. And then .Magnitude is taking the length of that 3D invisible “arrow.” Probing a bit deeper, we find this can be redone be manually calculated by ourselves like this:

local partA = game.Workspace.partA
local partB = game.Workspace.partB

local distance = math.sqrt((partA.Position.X - partB.Position.X)^2 + (partA.Position.Y - partB.Position.Y)^2 + (partA.Position.Z - partB.Position.Z)^2)

We can imagine the above geometrically. In a 2D version of the above, by only taking the difference on each axis, you’d be finding two lines that almost form a triangle, but are missing a side. That side that’s missing is a line going directly from partA to partB! And if you remember from algebra/geometry, the way to find a missing side of a triangle given the two other sides is by using the pythagorean theorem, or a^2 + b^2 = c^2, which can be pretty simply changed (as shown in the code above) to work for Vector3 values and 3D space. And there you go - your own .Magnitude formula!

Just by diving deeper into research, we can find out so much about a single commonly overlooked function, and learn a lot along the way. After this, you could delve more into Vector math, read this devforum guide, or do anything you could imagine.

I hope this was of some help!