Make vector change by camera height

Hi, so I have a script that applys force to a part when it touches the player’s leg. I want it to apply force depending on how high or low the player’s camera is (i think its look vector)

Script:


local Angle = 25
Player.Character["Right Leg"].Touched:connect(function(hit)
	if TM.check() == "L" then return end
	if hit.Name ~= "TPS" then return end
	if Kick == false then return end
	local force = Player.Character["Right Leg"].CFrame.lookVector * power
	local angle = Vector3.new(4e+006,Angle,4e+006)
	Kick = false
	TM.ApplyForce(hit, angle, force, "Right Leg")
	Kick = false
end)

Any help would be appriciated, thanks!

The look vector will always be a unit vector, meaning that it will always have the same length as one, instead of using a look vector you will want to get the difference In height between the camera and some reference point like the character or floor. so

local force = (Camera.Y - ReferencePoint.Y) * power

But you might want to cap the power and also stop the ball from going backward if the camera is below the reference point so

local force = math.clamp((Camera.Y - ReferencePoint.Y) * power,1,MaxDistance) * Power

What reference point of the charater should I use, and what is this?

And I get this error when using this

Sorry I misread a bit, The easiest reference point would be their character and then to fix my mistake

local magnitude = math.clamp((Camera.Y - ReferencePoint.Y) * power,1,MaxDistance)  * power
local force = Player.Character["Right Leg"].CFrame.lookVector * magnitude

And what is maxdistance?

charlimit

Just set it to the maximum distance between the reference point and your camera, if you can zoom really really far out then you don’t want the player to kick the ball at Mach 10 so that’s just there to limit it, if you want no limit you can just set it to math.huge

I have been trying to make this work for 6 days and it just doesn’t work

Here is my current script:

Player.Character["Left Leg"].Touched:connect(function(hit)
	if TM.check() == "R" then return end
	if hit.Name ~= "TPS" then return end
	if Kick == false then return end
	local Camera = game:GetService("Workspace").CurrentCamera.CFrame
	local magnitude = math.clamp((Camera.Y - Player.Character["Left Leg"].CFrame.Y) * power,1,1)  * power
	local force = Player.Character["Right Leg"].CFrame.lookVector * magnitude
	local angle = Vector3.new(4e+006,Angle,4e+006)
	Kick = false
	TM.ApplyForce(hit, angle, force, "Left Leg")
	Kick = false
end)