Let’s brief y’all on the scenario before I give you my question. I have a gun system that uses the following to move the bullet (it is designed to reflect based on Crazyman32’s Tutorial):
-- Cast ray:
local ray = Ray.new(currentPos, currentNormal * (overrideDistance or stepDistance));
local hit, pos, norm = game.Workspace:FindPartOnRayWithIgnoreList(ray, globalIgnoreList);
-- Update laser position:
bullet.Size = Vector3.new(0.15, 0.15, ((pos - currentPos).magnitude));
bullet.CFrame = CFrame.new(currentPos:lerp(pos, 0.5), pos);
local oldPos = currentPos;
currentPos = pos;
-- If hit do...
if (hit) and (stepCM <= stepMax) then
stepCM = stepCM + 1;
hitpart = hit;
-- Can we reflect it?
local canRef = bulletHit(currentPos,hitpart,currentNormal,settings);
if canRef == false then bullet:Destroy(); return end
-- r = d - 2(d DOT n)n
-- Reflect:
local reflect = (currentNormal - (2 * currentNormal:Dot(norm) * norm));
currentNormal = reflect;
Step(stepDistance - (pos - oldPos).magnitude);
return;
end
Essentially, I want to know if lerping with a CFrame is going to put more stress on the server than if I was using a Tween. (Which would also personally be easier for me to calculate mathematically)
I will take anything, no matter how difficult, to reduce stress on the server by the highest amount.
Note: For anyone questioning as to why the calculations and effects are done on the server, it’s for a multitude of reasons. Thank you.
I think that TweenService has a ton of overhead created along with tweening the cframe. Lerping is just using a function to interpolate between two oriented points and doing it repetitively.
e.g.
For TweenService:
Create CFrameValue
Set its starting value
TweenService:Create is called, returning a tween
Tween is immediately played
For Lerping:
Create CFrame variable
CFrame:Lerp is called 60 times/sec, returning a lerped CFrame, in which:
a. CF1*(1 - a) + CF2*(a) as reference function for position
b. probably some trigonometric function/identity to solve for angle vectors.
Less steps usually mean less computation, and less instantiating of objects also mean less for the memory to account for.
The computational expense involved behind the TweenService API is negligible in comparison to lerp, if there is any in the first place. I generally don’t agree with the sentiment that “less steps equals less computation”, it’s not necessarily substantiated.
Just let the client handle any kind of tween work, as it should. The server won’t waste memory trying to create an effect and the server doesn’t need to stress with something that doesn’t affect it. If everyone needs to see it, use a remote and let the other clients handle the parts.