I’ve already attempted this, but the code, for one, sends the projectile through an arc ending at the mouse’s hit point, and two, due to me using lerp as I don’t know how else I would move the rock, it slows down greatly before hitting the end point.
How could I make the rock follow the angle of fire and move at a constant speed?
Code:
while 5==5 do
pChar=player.Character
local P1=pChar.HumanoidRootPart.Position
local sH=(mhit-P1).Magnitude
local sO=mhit.Y-P1.Y
local theta=math.asin(sO/sH)
ex=( Vector2.new(rock.Position.X,rock.Position.Z) - Vector2.new(mhit.X,mhit.Z) ).Magnitude
local rockheight=(ex+math.tan(theta)-
((workspace.Gravity*ex^2) / ( 2*(Velocity^2)*( math.cos(theta)*math.cos(theta) )) )
)
desiredpos=Vector3.new(mhit.X,rockheight,mhit.Z)
rock.CFrame=rock.CFrame:Lerp(CFrame.new(desiredpos),.1)
print("(",P1,")",theta,ex,rockheight," (",rock.Position,")")
task.wait()
end
Incase there’s any confusion, this is encased in a function with “player:Player, mhit:Vector3, rock:Instance” in the parenthesis.