So I’m trying to get the time that my NPC takes to walk between waypoints, but it has some issues
Code
local function getCFrameMagnitude(cf,cf2)
local axis,theta = cf:ToAxisAngle()
local axis2,theta2 = cf2:ToAxisAngle()
return (cf.Position-cf2.Position).Magnitude,((axis*theta)-(axis2*theta2)).Magnitude
end
local function GetTimeToCoverWaypoints(waypoints: Model, walkspeed: number, rootPart)
local t = 0
--
for i = 1, #waypoints:GetChildren() do
local nextWaypoint = waypoints:FindFirstChild(tostring(i + 1))
local currentWaypoint = waypoints:FindFirstChild(tostring(i))
if nextWaypoint then
local distance = getCFrameMagnitude(currentWaypoint.CFrame, nextWaypoint.CFrame)
local timeElasped = math.ceil(distance / walkspeed) + 0.05
t += timeElasped
end
end
return t
end
Why are you rounding the value for timeElapsed up and adding a 0.05. Are you rounding up for a clean number and then the 0.05 as an error margin? Try removing the ceil function maybe. If you wanted to have a clean number you could multiply the inside number by 10 and then divide it by 10 on the outside and that would round it to one decimal place.
local timeElapsed = math.ceil(distance / walkspeed * 10)/10
Still having a difference, I think I need to count the friction & the time that the humanoid takes to turn around in the corner waypoint, it also needs to count the engine speed when listening new event subscriptions.
By what % is if off by? And how exact does the solution need to be?
Basically, I’m creating an NPC system that the only the client can see, and the server will provide the waypoints, if the player shoots, the server creates hitboxes but needs the most similar position based on the time that the NPC has existing lifetime - playerLatency
.
BTW: I just noticed that I don’t need this thing, just testing and then I do it in the inverse side, I will make a new post of how to get a position based on the waypoints & npc lifetime(with speed?)