I’m making a script for choose the distance of a catapult (Z axie) to fire , but i have two problems
1- I need a way to determinate a value limit to Z ,example (-0.5 until 0.5)
2- Need find Delta using Pythagorean theorem to get correct Z,X position
Client Script:
UserInputService.InputBegan:connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.W then
while true do
if AxisUP >= 0.1 then
AxisUP = 0.1;
workspace.Catapult.SetPosi:FireServer(AxisUP,AxisH)
else
AxisUP = AxisUP + 0.005
workspace.Catapult.SetPosi:FireServer(AxisUP,AxisH)
end;
RunService.RenderStepped:wait();
if UserInputService:IsKeyDown(Enum.KeyCode.W) == false then
break;
end;
end;
elseif input.KeyCode == Enum.KeyCode.S then
while true do
if AxisUP <= -0.1 then--limit
AxisUP = -0.1;
workspace.Catapult.SetPosi:FireServer(-AxisUP,AxisH)
else
AxisUP = AxisUP - 0.005
workspace.Catapult.SetPosi:FireServer(-AxisUP,AxisH)
--workspace.Catapult.Target.Position = Vector3.new(workspace.Catapult.Target.Position.X-AxisUP*3,workspace.Catapult.Target.Position.Y,workspace.Catapult.Target.Position.Z)
end;
RunService.RenderStepped:wait();
if UserInputService:IsKeyDown(Enum.KeyCode.S) == false then
break;
end;
end;
end)
Server Script:
SetPosition.OnServerEvent:Connect(function(plr,axisUP,axisH,targetPos)
AxisUP.Value = axisUP
print(AxisUP.Value)
if AxisUP.Value<= 0.1 or AxisUP.Value >= 0.1 then
else
target.Position += Vector3.new(0,0,AxisUP*5)
end
---------------------------------------
AxisH.Value = axisH
rotation = CFrame.Angles(0, AxisH.Value , 0)
Catapult:SetPrimaryPartCFrame( hrp * rotation )
end)