I’ve been trying to create a projectile that is controlled by the server. The problem is that I need the projectile to look at a position, and I’m not manually setting the CFrame since physics replicates much faster (body movers, vector forces, etc).
Initially, I did the CFrame manually on the server, but as I said, it was too laggy for my liking.
I then tried rendering the projectile on the clients, but when I compensated for lag, the latency from client-server-clients was too high on average to be sustainable, as the game requires quick reaction time to these projectiles (its a football and the ball would spawn too far ahead for very short passes).
Lastly, I went to using a body movers, but the gyro will not align the projectile angle correctly and fast enough, which I believe is due to very small changes in the CFrame (keep in mind I can’t just increase dampening because I need this to instantly align to the desired orientation).
I did notice significant lag improvement with the body movers (I also read somewhere it just simply replicates faster), so I would like to find a way that doesn’t involve going back to manually setting the CFrame.
tl;dr
I need the projectile to angle instantly towards a position using some form of body movers (stuff that uses physics).
Current Projectile Code
local module = {}
local bullets = {} --holds all projectiles
function module.Render(last) --called every physics step and last is the delta time
if #bullets > 0 then
for index, data in pairs(bullets) do
if data.Tracer and data.Tracer.Parent then
local tracer = data.Tracer
data.Time = data.Time + last
local wobble = math.sin(data.Spin * data.Time * 60 / 100) * 15 --Creates a wobble effect on the football, works fine when I manually set the CFrame
tracer.Thrust.Velocity = data.Aim * 70 - Vector3.new(0, .2 * data.Time, 0) --Aim is a unit vector for where they threw and .2 * data.Time represents drop
tracer.Orientate.CFrame = CFrame.new(tracer.Position, tracer.Position + tracer.Thrust.Velocity) * CFrame.Angles(math.rad(90 + wobble), math.rad(data.Spin * data.Time * 60), math.rad(wobble)) --Want the football to look to its next position
end
end
end
end
function module.new(player, stat) --player is who threw and stat is data for the projectile
local tracer = stat.Tracer:Clone() --just the football part
tracer.Parent = workspace
tracer.Position = stat.Origin --initial position of where it was thrown
stat.Tracer = tracer
stat.Time = 0 --holds time since thrown
tracer.Thrust.Velocity = stat.Aim * 70 --Body Velocity, is not the problem here
tracer.Orientate.CFrame = CFrame.new(tracer.Position, tracer.Position + tracer.Thrust.Velocity) * CFrame.Angles(math.rad(90), 0, 0) --Body Gyro, will not align fast enough and when I make it faster it doesn't do it correctly
tracer.Anchored = false
tracer:SetNetworkOwner(nil)
table.insert(bullets, stat)
end
return module
Thanks