my equation is stated below, it calculates the distance the ball is required to travel, and increase the velocity dependent on the distance, however i am making a basketball game, that has varied air resistance due to different locations, it says that i am "attempt to perform arithmetic (mul) on number and Instance"
local t = 1;
local mouse = game.Players.localPlayer:GetMouse();
local hrp = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("HumanoidRootPart");
local bball = game:GetService("ReplicatedStorage").ball;
local active =false
local speed = 100
mouse.Button1Down:connect(function()
if active == false then
active = true
local tar = (mouse.hit.p - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if tar < 50 then
t = 1
elseif tar >60 and tar< 90 then
t = tar/speed
elseif tar >90 then
t = 4
end
local g = Vector3.new(0,-game.Workspace.Gravity,0)
local x0 = hrp.CFrame *Vector3.new(0,2,-2) -- setting the position for starting place of the ball
--calculate the v0 needed to reach mouse.hit.p
-- local v0 = (mouse.hit.p - x0 - 0.5*g*t*t)/t -- the calculation to find initial velocity needed to reach a certain target in a given time
-- have the ball travel the path
local rho = 1.2 --density of air
local r = 0.017 --area of item
local c = 0.47 -- drag coefficient
local A = math.pi*r^2
local v0 = (mouse.hit.p - x0 - 0.5*g*t*t)/t
if tar/10 >2 then
game.Players.LocalPlayer.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
wait()
game.Players.LocalPlayer.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
end
local c = bball:Clone();
c.Velocity = v0 - 0.5*rho*A*c*(v0).magnitude^2*v0;
c.CFrame = CFrame.new(x0);
c.CanCollide = true;
c.Parent = game.Workspace
wait(t)
active =false
print(tar)
print(t)
t = 1
end
end)
thankyou in advance :)
