x0 stands for Initial position, if you scroll a tiny bit up you’ll see what the other kind of 0 mean.
This is great! I was able to make some really nice looking bullet sparks and bullet drop using this.
i think he just meant the code is a bit hard to understand with the variables like x0 and v0
if anyone is having issues with this not working for freshly instanced in parts, the issue is you need to parent the object to workspace before setting the velocity
Decided to try this for myself too. Can confirm that this formula works great for gun sparks!
Yours is much better, however!
It doesn’t really matter since I stopped working on the game anyways.
Hi there. Great post! I really like how each step and formula is explained in-depth so we can understand the inner-workings of the code as we progress through the tutorial.
Would it be possible to achieve the same effect but by using VectorForce
s instead of Velocity
? I want to have a projectile travel with a constant velocity until the point-of-contact instead of giving it a single force at the beginning. Plus, it would allow for drag and acceleration which isn’t possible by setting the velocity independently.
By playing around with the sample code at the end, I was able to create this using VectorForce
s:
mouse.Button1Down:Connect(function()
local g = Vector3.new(0, -game.Workspace.Gravity, 0);
local x0 = hrp.CFrame * Vector3.new(0, 2, -2)
-- calculate the v0 needed to reach mouse.Hit.p
local v0 = (mouse.Hit.p - x0 - 0.5*g*t*t)/t;
local c = bball:Clone();
c.CFrame = CFrame.new(x0);
c.CanCollide = true;
local attachment = Instance.new("Attachment")
attachment.Parent = c
local vectorForce = Instance.new("VectorForce")
vectorForce.Attachment0 = attachment
vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
vectorForce.Force = v0 + Vector3.new(0, 2096, 0)
vectorForce.Parent = c
c.Parent = game.Workspace;
end)
I don’t know why the addition + Vector3.new(0, 2096, 0)
is just about the right number for the VectorForce
to generate enough force to keep the object in the air. Without it, the object would drop out of the air because it doesn’t have enough vertical force. Any help would be greatly appreciated!
Yes, but I’m not sure if it would work as well. It could potentially be smoother (I’d have to check when I have time), but given that a VectorForce applies force constantly rather than changing velocity, you could run into some problems.
The reason why the addition + Vector3.new(0, 2096, 0)
is just about the right number is most likely because its the closest number to the part’s Mass * workspace.Gravity
, which would be the exact opposite of the force applied to the ball by gravity, therefore cancelling the gravitational force out. If you want it to be more accurate then you can always do
vectorForce.Force = v0 + Vector3.new(0, c:GetMass() * workspace.Gravity, 0)
rather than using the set value. This also allows you to use a different ball size or material, since changing those would change the mass of the ball, therefore changing the number from 2096.
Hope this helped a bit. (im certainly not helping myself since im procrastinating again)
I’m not more of a mathematic person but
how would I make it so it’s based on where my camera is facing Up and Down
https://gyazo.com/919f96b8f599267a75b0d65d071a4bf3
game:GetService("RunService").RenderStepped:Connect(function(dt)
local g = Vector3.new(0, -game.Workspace.Gravity, 0);
local x0 = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * Vector3.new(0, 2, -2)
local Camera = game.Workspace.CurrentCamera.CFrame
local rootPart = game.Players.LocalPlayer.Character.HumanoidRootPart
local v0 = (rootPart.CFrame.LookVector * Vector3.new(-UpOrDown(Camera.LookVector),0,-UpOrDown(Camera.LookVector)) * 50 - 0.4*g*t*t)/t;
local curve0, curve1, cf1, cf2 = beamProjectile(g, v0, x0, t);
beam.CurveSize0 = curve0;
beam.CurveSize1 = curve1;
attach0.CFrame = attach0.Parent.CFrame:inverse() * cf1;
attach1.CFrame = attach1.Parent.CFrame:inverse() * cf2;
end)
I am solving for time using t = distance/initial velocity to have the ball be thrown at a given initial velocity all the time but for some reason the farther I throw the ball, the more it deviates from the given initial velocity. like at short distances, the velocity it outputs matches what I give it.
what do I fix in my time equation to not make that happen? or maybe im totally doing it wrong, i just want to throw a ball 43m/s everytime.
Sorry im late: Whats this formula called? I want to understand the basics of the equation other than understanding what each part does.
Its a branch of math called calculus. He says so here
Hey, I have a question, what If I try to use that motion effect for Dummies/Character as a type of Dynamic knockback, would it be possible? I’m trying to figure out for 2-4 months how to make something like that, but I do not know how to exactly do it, because it bounces and the character/dummy’s head is always pointed to the ground where’s the position that it will fall.
If you can give me a idea or a done code already, this will help me alot, I tried to use bezier curves but I realised that this would not be so efficient and does not helped me, i’m not a really advanced scripter but I know some things on roblox, but i’m just out of ideas.
This is the knockback at the video I want to recreate (This was not made by me):
hey i cant get the model, is there a specific reason for this, or did u take it down on purpose?
should be enabled now, it probably got disabled when Roblox did a Marketplace update or smt
omg thank you so much, ily (no homo)
how do i make it so the beam isnt a straight line when looking at the sky and it has like a limit if you know what i mean?
What is X0 and how do i get it?, and is V0 velocity?
attempt to perform arithmetic (add) on number and Vector3
local p3 = 0.5*g*t1*t1 + v0*t1 + x0;