How change Delta (Magnitude)?

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)

image
image

I dont understand? :confused: Can you help me?

what you cant undestand ? ? :face_with_raised_eyebrow:

what are you trying to achieve by getting the delta with the pythagorean theorem

The correct Distance between catapult and target part

if i’m understanding correctly you would do

(targetpart.Position - catapult.Position).Magnitude

image

I want that

(EndVector - StartVector) will give you the vector containing the delta value.
In order to get the length of said vector just do:
(EndVector - StartVector).Magnitude

Ok i think thats resolve my 2nd problem, but i still need a way to determinate Z between limits

Uh, try find the line distance

green line ^ 2 = Z^2 + X^2

Do you mean to clamp the Z value? If your catapult doesn’t rotate then I’d suggest simply using math.clamp on your Z value. Otherwise, then it becomes a bit more complicated. I’m not sure I’d be able to help right now since I’m on my phone…

it does thats why i need limits to target part and a way to change his position in delta