Trying to model a projectile's movement over an arc

On the server, i create an arc out of rays to emulate the path of a projectile. On the client, it receives an event to replicate this with a part, which is supposed to follow the path of the projectile. The problem is, i cant quite seem to get them to line up like they should. I have tried changing and adding values in the client to try and get it close enough, but i feel like this is a sketchy way of doing it and it hasn’t produced any accurate results anyhow. This is what i use on the server to create the projectile:


--methods used
local function CalculateStartVelocity(pos, goal, power, accuracy)
	local maxAngle = math.rad(125)*math.clamp(1 - accuracy, 0, 1)
    return (CFrame.new(pos, goal)*CFrame.Angles(0, 0, math.random(0, 2*math.pi))*CFrame.Angles(math.acos(math.random(math.cos(maxAngle), 1)), 0, 0)).LookVector*power
end


local function CalculateProjectilePosition(startpos, startvelocity, timeSince,gravity)
	return startpos + startvelocity * timeSince + 0.5 * gravity * timeSince ^ 2;
end

local function GetAllParts(Ray)
    local Parts = {}
    local LastPart
    
    repeat
        LastPart = workspace:FindPartOnRayWithIgnoreList(Ray, Parts)
        table.insert(Parts, LastPart)
    until LastPart == nil

    return Parts
end




game.ReplicatedStorage.ServerRemotes:WaitForChild("Fire").OnServerEvent:Connect(function(plr, bullet, pos, baseDmg, speed, punch)
	local bolt = bullet
	local col = punch or 1
	
	
	
	if bolt:FindFirstChild("BodyForce") then
                
		local CurrentPosition = pos.p
		local LastPosition = CurrentPosition
		local StartVelocity = CalculateStartVelocity(pos.p, pos.p + pos.LookVector * 1, speed, 1)
		
		
		ReplicatedStorage.ServerRemotes.Fire:FireAllClients(bolt, pos, speed)
                --Message to client to replicate the projectile, bolt is the part prefab for the bullet, pos is the
                --CFrame of instantiation, and speed how fast the projectile will move. 
		
		for i = 1, 50 do wait(0.01)
			CurrentPosition = CalculateProjectilePosition(LastPosition, StartVelocity, (0.1 * i), Vector3.new(0, workspace.Gravity * bolt:GetMass() * bolt.Drop.Value, 0))
			
			local ray = Ray.new(LastPosition,CurrentPosition-LastPosition);
			
			
			LastPosition = CurrentPosition
		end
		
		
	else
		warn("No BodyForce for bullet; add to prefab")
		bolt:Destroy()
	end
end)

This is what i use on the client to try to copy its path

local remote = game.ReplicatedStorage.ServerRemotes.Fire
local Debris = game:GetService("Debris")

remote.OnClientEvent:Connect(function(projectile, pos, speed)
	local bolt = projectile:Clone()
	
	
	bolt.CFrame = pos
	bolt.Velocity = pos.LookVector * speed * 2.5
	if bolt:FindFirstChild("BodyForce") then
		bolt:FindFirstChild("BodyForce").Force = Vector3.new(0, workspace.Gravity * bolt:GetMass() * bolt.Drop.Value/50, 0)
		--I tried messing with these to line up the path ^^^
		bolt.Parent = game.Workspace
		Debris:AddItem(bolt, 3)
	else
		bolt:Destroy()
	end
end)

I put tracers in the code to visually represent both paths (red is server, blue is client)
robloxapp-20200326-0826567.wmv (1.2 MB)

Should i try to make this arc on the client, and then put a bodyPosition/anchor and increment position as the arc progresses instead (i feel as though this would take more resources from the client, and would look less smooth anyway, and would be much more buggy)

EDIT: The cubes along the paths represent the vertices of the arc, which are created every .01 seconds

1 Like

I have done what i have suggested above ^^. its not pretty, but it will do for now. (Looking at this system, it seems very similar appearance wise to Jailbreak’s projectile system, just thought i would point that out)

EDIT: im going to leave this unsolved, as i am still interested in finding a solution to this.