I’ve been trying to modify the magnitude of a curve force on a football. I’ve only gotten the direction so far:
local function GetCurveForce(ball: BasePart, limb: BasePart) -- returns the magnitude of rotational force to the ball.
local direction = CFrame.new(limb.Position * Vector3.new(1, 0, 1), ball.Position * Vector3.new(1, 0, 1)).LookVector -- gets lookvector for comparison
local rightvector = humanoidrootpart.CFrame.RightVector
local diff = -direction:Dot(rightvector) -- get dot product of direction and rightvector to get direction of curve
if diff > 0 then -- decides which direction to curve
diff = 1
else
diff = -1
end
local curveforce = ((diff) * (power))
return curveforce
end
I believe you meant torque, force when it’s rotational is called torque.
Adding a distance factor should be enough like so:
local XZ_Vector = Vector3.new(1,0,1) --Keep the distance measured on a 2d XZ plane
local function GetCurveForce(ball: BasePart, limb: BasePart) -- returns the magnitude of rotational force to the ball.
local direction = CFrame.new(limb.Position * Vector3.new(1, 0, 1), ball.Position * Vector3.new(1, 0, 1)).LookVector -- gets lookvector for comparison
local rightvector = humanoidrootpart.CFrame.RightVector
local diff = -direction:Dot(rightvector) -- get dot product of direction and rightvector to get direction of curve
if diff > 0 then -- decides which direction to curve
diff = 1
else
diff = -1
end
--Measure distance from a birds eye view,
local torqueRadius = (ball.Position - limb.Position)*XZ_Vector.Magnitude
torqueRadius = math.max(1,torqueRadius)
--apply distance factor
local curveforce = ((diff) * (power)) * torqueRadius
return curveforce
end
However if you notice if you are at 0 distance there would practically no Torque.
to solve this there are multiple ways, you could perform add a flat value or math.clamp the value or even do the thing below to transform 0 into a value like 1. The simplest should be math.max to choose the biggest number.