NOTE: I do not have code, I was super stuck on how to do it so I am asking here. YouTube has nothing, so that’s all.
I am trying to create a Molotov but I don’t know how to throw the molotov to the mouseposition with velocity. I was just thinking of using first person, but at the same time that prevents people who like 3rd person from doing their thing.
Let me put it this way for those confused: You click, you get the mouse position. You create a velocity that throws the molotov, to wherever the person clicked (of course with there being gravity).
local mouse = game.Players.LocalPlayer:GetMouse()
print(mouse.Hit.Position) -- mouse.Hit is a CFrame
If you wanted it to be like a Roblox phyiscs throw you could do model/part :ApplyImpulse((mouse.Hit.Position-player.Character.HumanoidRootPart.Position)*Power)
This is what it might look like if you manually animated it.
In this example, you would pass the model of the object, the current CFrame (usually), the CFrame you want to end at, the amount of distance you want it to arc upwards, and the time it takes to get there.
Also in this example it uses RenderStepped which is a client-sided only event so you would do it in a LocalScript and you would not see it animate on other clients (or other players).
local rs = game:GetService("RunService")
local function Animate(objectModel, fromCf, toCf, bowing, time_to)
local t = 0
local ht = time_to/2
local con = nil;
con = rs.RenderStepped:Connect(function(dt)
t = t + dt
if t > time_to then con:Disconnect(); end
local y = t/ht
if t > ht then y = 2 - y end
y = y*bowing
objectModel:PivotTo(fromCf:Lerp(toCf, t/time_to) + Vector3.new(0,y,0))
end)
end
But you need to tell which direction to begin throwing. So in this example I’ll just assume the current CFrame is the direction you want to throw it in with preset up and forward power values.
local ForwardPower = 10
local UpPower = 8
bv.Velocity = handle.CFrame.LookVector*ForwardPower + Vector3.new(0,1,0)*UpPower
then parent the bv so it’s inside the handle
bv.Parent = handle
Now add a touch event to see when it lands
local con, notTouched = nil, true
con = handle.Touched:Connect(function(part)
if not part.Parent:FindFirstChild("Humanoid") then
notTouched = false
con:Disconnect()
script:Destroy()
end
end)
Finally loop according to acceleration of gravity. (or maybe slower)
while notTouched do
local t = wait()
bv.Velocity = bv.Velocity - Vector3.new(0,16*t,0)
end
So the trigger was placing it into workspace from your character (just tested)
So you want the Tool (when left click) to be CFrame positioned and then placed into the workspace.
local molotov = script.Parent
local handle = molotov.Handle
repeat wait() until molotov.Parent==workspace
local bv = Instance.new("BodyVelocity")
local ForwardPower = 10
local UpPower = 8
bv.Velocity = handle.CFrame.LookVector*ForwardPower + Vector3.new(0,1,0)*UpPower
bv.Parent = handle
local con, notTouched = nil, true
con = handle.Touched:Connect(function(part)
if not part.Parent:FindFirstChild("Humanoid") then
notTouched = false
con:Disconnect()
bv:Destroy()
script:Destroy()
end
end)
while notTouched do
local t = wait()
bv.Velocity = bv.Velocity - Vector3.new(0,16*t,0)
end
LocalScript:
local UIS = game:GetService("UserInputService")
local Tool = script.Parent
UIS.InputBegan:Connect(function(inp, gpe)
if gpe then return end
if Tool.Parent:IsA("Model") then
if inp.UserInputType == Enum.UserInputType.MouseButton1 then
local ccf = Tool.Handle.CFrame
Tool.Handle.CFrame = ccf
Tool.Parent = workspace
end
end
end)
I wouldn’t be able to imitate or improve what was done in the post. I don’t know of a way to more easily implement what was shown. If I had to send something from Point A to Point B it’d be done using a simple straight line with a BodyVelocity because I don’t have experience with constraints.
The method explained in the above replies might work just as well, I haven’t tested anything.