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.
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
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?
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?
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?
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!
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
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?
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.
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.
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?
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:
…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.
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.