The "getPedTargetStart" function will retrieve the starting point of the target range. This target range is probably linked to the camera position (I'm not entirely sure though), which would explain why your camera is "always moving forward"
Let's say the target start range is always 1 unit in front of the camera. Your camera position is set to 0. Then you set the camera position to the start range (1), and the start range then subsequently changes to 2. This will happen forever whilst you are zoomed in.
You should store the initial target start position, instead of getting it on each frame. This can be done quite easily.
local targetStartPos = false
function aim_test ()
if getControlState("aim_weapon") == true and getPedWeapon(localPlayer) == 34 then
if not targetStartPos then
local startX, startY, startZ = getPedTargetStart(localPlayer)
targetStartPos = {x = startX, y = startY, z = startZ}
end
local x, y, z = targetStartPos.x, targetStartPos.y, targetStartPos.z
local x2,y2,z2 = getPedTargetEnd(localPlayer)
if not x2 then
return false
end
local x3,y3,z3 = getPedTargetCollision(localPlayer)
if x3 then
setCameraMatrix(x,y,z,x3,y3,z3)
else
setCameraMatrix(x,y,z,x2,y2,z2)
end
else
if not getCameraTarget(localPlayer) then
targetStartPos = false
setCameraTarget(localPlayer)
end
end
end
addEventHandler("onClientPreRender",root,aim_test)
Haven't tested, but I'm fairly certain that should fix your issue.