Need help with advanced math

Hey, I am a pretty good scripter myself.
But math is extremely confusing in Roblox such as division, bodmas.
Now, I did learn these in school but I just need help with using it the “advanced way”, like:

local x = 10
local rate = 1/100

local thing = x * rate / x

This is literally my weakness in scripting. I just can’t understand it properly.
Like I ask myself, “why do you multiply x and divide it by rate like what does that do”

I know I may not have said this correctly, but I hopefully made my problem make sense to be solved.
It’s just, I know what BODMAS, division, multiplication and such, but I am not sure how to use it in a script for like a combat system or something.

I hope this made sense.

5 Likes

if you need to define whatever order of operations you want you can use parentheses. it’s especially useful for division where a / b / c could be either (a / b) / c or a / (b / c).

also, your code x * rate / x
would always result in the x’s cancelling out, like so
x * (rate / x) or (x * rate) / x

4 Likes

So from what I understand you mean is how to make math ‘logical’?

If thats so you can try

local thing = (x * rate) / x

This will first do x * rate then divide it by x.

If you dont add them it will cancel eachother (x) out and it will only be rate which is 1/100 in this case.

So you see its just bodmas or if you use brackets

Oh and before I forget.
rate is a fraction so it will be

thing = 10 * (1/100) / 10

Hope this helped!

4 Likes

That made a lil bit more sense, but I am confused on why you have to use maths to get a result for soemthing? I usually seem them for Runservice “deltaTime”, they usually divided delta time and multiply it by a number, and then so im asking “why do you need to do that maths for delta time??”
Maybe you can add on?

2 Likes

You mean Δt?

If so the formula for it is t2 - t1 (time 2 minus time 1)
I’m just guessing here?

2 Likes

Not really, but i am definitely not good at maths for scripting, its just im asking myself why you need maths to do a result, you get what I mean? like "x * (b / a) what does that have to do with anything?

1 Like

Well, maths can be very very useful in scripting such things as speed.
I once made a rocket which tweens but I wanted the tween to be at a constant speed even how far it was so I used a formula (math)

Or when I also made an xp system based on your level eg.

Level = 10
-----------
XP needed for next level

formula = (lvl * 10)/2
which is 50 xp.

Does this give you any more information on why and how to use it?

1 Like

I think things are coming together now!
Oh yeah, why would you need to multiply then divide it?

1 Like

Well to kind of add randomness and precision
If I thought: ‘oh! 100xp thats too much’
then I just divide it by 2.
Why I dont use minus is because if someone is a higher level

lets take lvl 100
the -50 I added will do nothing.
Thats why!

1 Like

If you did physics math and learned basic algebra, then it would be easier to explain

if you dont know what your variables do, write em with comments

local acceleration = 1/100 -- 1 meter / 100 second^2
local deltaTime = 2 -- 2 seconds

-- i need to find delta velocity omg!!!
-- remember: deltaVelocity = acceleration * deltaTime, and velocity is in m/s
local deltaVelocity = acceleration * deltaTime -- 1m / 100s^2 * 2s = 1m / 50s = .02m/s
1 Like

That is making a bit more sense, but how does multiplying the accel * time work? how does the velocity work? I read the comment, and I do understand it but how does it work?

1 Like

that’s some basic logic. acceleration is an addition to the velocity as time goes. also like, if you have something in m/s^2, and you have something in s, how would you get something in m/s? just multiply m/s^2 with s, whichis m/s. that is what i meant by basic algebra.

1 Like

Well, the delta is because of this, RunService’s events are called very frequently per second, so it provides a delta which is usually a fraction of a second (0.03) or so and it’s how long it’s been since the last call. If you didn’t multiply all the numbers by that delta, then you would be running that code as if it was ran every second (1 * x = x).

Say you wanted to move a part forward 30 studs per second, but very smoothly, so you think: "I will put it in a .Heartbeat event. You would be wrong, this would call it every frame, and that would be WAY too fast. Instead, you multiply it by the delta: position + (30 studs) * delta.

This will scale it down to the speed that it’s called. If it’s called twice per second (2 fps) then the delta will be on average about 0.5. 30 studs * 0.5 = 15 studs. So instead of every 1 time every 1 second, you call it twice every half a second.

1 Like

The meaning of velocity is how fast and the direction something travels per unit, but usually it’s just assumed per second. That’s why they say miles per HOUR, not second.

If I said my velocity was 2 meters going south, I would still need to specify the interval that was happening at. Is it per second? Minute? Hour?

Any other questions?

1 Like

Roblox LuaU, like most other languages, processes mathematical expressions according to the rules of Algebra. So PEMDAS is in use (I know other countries call it other things, but I’m in the United States). So PEMDAS is this:

P: Parentheses ()
E: Exponets x²
MD: Multiplication/Division * /
AS: Addition/Subtraction + -

Your code that you posted…

…will result in thing = rate because since only multiplication and division are involved, the x drops out and you’re left with just rate. So beyond that, what help do you need?

EDIT:

In reading the other comments, velocity and acceleration are two different things. From Calculus, velocity is how fast something is moving and acceleration is how fast the velocity is changing. Consider the following formula:

  • y = -½at² + tv + yo

This is the classical newtonian formula for motion. It breaks down as follows:

  • a: Acceleration, usually due to gravity. You would get this from game.Workspace.Gravity.
  • t: Time in seconds.
  • v: Velocity. Velocity has both a horizontal and vertical component. You use the trigonometric functions sine and cosine to get those components. But in Roblox, parts have a AssemblyLinearVelocity that breaks the velocity out as a (x, y, z) triple.
  • yo: Starting Y position.

There’s other things to consider too such as F=ma which is Force = Mass * Acceleration. So you can use something like force = Vector3.new(0, part.Mass * game.Workspace.Gravity, 0) to make the part float.

When you work with Vectors and Coordinate Frames (CFrames), then linear algebra and calculus comes into play.

velocity doesn’t need to define the direction, also the sentence “2 meters going south” is morelikely a distance instead of velocity. also we talking about physics here, so we use m/s more.

Replies above are helping me out a lot, im sure you guys find it pretty annoying because I can’t understand it. But the thing i am trying to solve is why you need maths to do something.

I’m not talking about physics, just the velocity individually, and velocity does have to include direction.

image

When i say “2 meters going south” I include the direction and distance, but I leave out the time to explain why it’s so important, it’s not speed without time (rate).

i did not say you were talking about physics, in this thread i’m using physics as an example. also, im not sure if anyone defines velocity with a direction. sorry if i dont understand something.

Umm… Actually, velocity does include the direction. It’s defined in physics that way.

1 Like