What do you want to achieve?
I’m trying to calculate the velocity of a part and simulate how ROBLOX calculates it internally. My main question is wondering how does ROBLOX calculate the velocity of a part internallly?
What is the issue?
I’ve done some research and my calculated velocity does not line up with the velocity ROBLOX gives me.
-- // Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- // Vars
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
local HumanoidRootPart = Character.HumanoidRootPart
-- //
local function CalculateVelocity(Before, After, deltaTime)
-- // Vars
local Displacement = (After - Before)
local Velocity = Displacement / deltaTime
-- // Return
return Velocity
end
-- //
local PreviousPosition = HumanoidRootPart.Position
RunService.Heartbeat:Connect(function(DeltaTime)
local CurrentPosition = HumanoidRootPart.Position
local Velocity = CalculateVelocity(PreviousPosition, CurrentPosition, DeltaTime)
PreviousPosition = CurrentPosition
print(HumanoidRootPart.Velocity, "---", Velocity)
end)
if the characters velocity is 0, 0, 100000 but there is a wall in front of them they will move 0, 0, 0 so the position change and velocity may not be the same
if your checking the Displacement on the server side then it will not be perfect due to ping because the client tells the server where the character position is and the time it takes for the server to receive that position is different depending on there ping
its possible for the cheater to keep there velocity at 0 and still change there position you cant trust the velocity or the position
this will not prevent exploiters a exploiters does not need to move there character to fire a touch event or proximity prompt or remote event etc…
here is a video i made that shows you how to make a anticheat