i want to know how gravity is added to a vector3, for example this code
, isnt yaxis just a number, gravity is a force so how?
also how the heeck is assembly mass added to a vector3? any help greatly appreciated, thanks.
If you wish to overcome the gravity and make the projectile stay at a certain height, you would have to multiply the mass by the Gravity property of the workspace and then add an amount on which will determine how fast the projectile moves. (When I have done this before I found low numbers worked well such as 1.85 otherwise the object moved too fast)
If you wish to apply gravity to an object and make it move down then I believe you should simply be able to subtract it.
What I think you’re talking about is resultant forces.
Vector3, when used as a velocity, all X, Y, and Z values are forces.
Use the force physics equation Force = mass x gravitational force to get the amount of force you need to negate the force of gravity. Then, to apply this, you add the additional force you require to that value.
Roblox’s default gravity value is 196.2 (roughly 54 m/s^2). You can change this in Game Settings.
Here’s an example to calculate force needed for a certain acceleration:
So, let’s say we have a part with a mass of 20. We use F = mg to determine the amount of force to offset the gravity:
F2 = 20 x 196.2
F2 = 3924
Then, let’s say we want an acceleration of 1. So, we use Force = mass x acceleration, and add the force pulling it down:
F1 = 20 x 1 (+ 3924)
F1 = 20 (+ 3924)
which gives us the amount of force we need to apply against the gravity force to get that acceleration.
I’ll use a part with a mass of roughly 20, and apply (3924 + 20) 3944 in the Y axis on a VectorForce applied at the centre of mass. I’ll also use a script here that prints the acceleration of the Part (SUVAT equations, acceleration = final - initial velocity / time elapsed).
Now, we eventually get a pretty reliable acceleration of 1! Keep in mind that it is not 100% accurate, I did use 20 as mass rather than 19.999, which was the actual mass of the block, and my method is not perfect so your acceleration may reach higher than expected.
You’ll notice if you try this for yourself, that if you use the gravity force offset (3924) without the additional acceleration (20), the object will of course not move, because you use an acceleration of 0, so the resultant force is 0.
Best of luck!
that helps visualize it especially with the equation bit. Im a bit tired right now so my brain isnt very awake but Ill make sure to look into it more later. Thanks again!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.