Inaccuracy between Server Character Position and Client Character Position

FIRST OF ALL THANKS FOR EVERYONE THAT READS THIS TOPIC

  1. What do you want to achieve?
    I want to update my character client position to my character server position

  2. What is the issue?
    Im currently working on a game that relies on fast movement and precision,but it seems like it’s not that accurate:

The RedPart is where the server sees my character, I want so Its almost in the same position as the character, basically clipping.

Why I want that? Imagine this are players. Player2 will always sees player1 as the RedPart, this would generate massive collision problems.

For an example in Blade Ball u get hit by the ball before it actually hits your character. “That seems to be a problem in Blade Ball but I can’t confirm or state it, I’m also not judging or complaining about the Blade Ball Collisions”

  1. What solutions have you tried so far?
    I’ve tried to implement an interpolation system using lerp or tween, but it doesn’t seems to work:

Server Side:

local runService = game:GetService('RunService')

local replicatedStorage = game:GetService('ReplicatedStorage')
local remotesFolder = replicatedStorage:WaitForChild('Remotes')
local unreliableUpdateLocation = remotesFolder:WaitForChild('UnUpdateLocation')

local lastUpdate = tick()
local diference = 1/30

game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(char)
		local red = Instance.new('Part', workspace)
		red.Color = Color3.fromRGB(255, 0, 0)
		red.Size = Vector3.new(3,3,3)
		red.Anchored = false
		red.CanCollide = false
		red.Transparency = 0.2
		
		runService.Heartbeat:Connect(function()
			local pos = char.PrimaryPart.Position
			red.Position = pos
			red.Rotation = char.PrimaryPart.Rotation
			
			-- UpdateLocation
			if (tick() - lastUpdate) > diference then
				unreliableUpdateLocation:FireClient(player, pos)
				lastUpdate = tick()
			end
		end)
		
	end)
end)

Client Side:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local linear = char.PrimaryPart:WaitForChild('LinearVelocity') 

local moveSpeed = 20
local mouse = player:GetMouse()

local tween = game:GetService('TweenService')
local info02 = TweenInfo.new(2, Enum.EasingStyle.Linear)
local info = TweenInfo.new(0.25, Enum.EasingStyle.Linear)
local runService = game:GetService('RunService')

local replicatedStorage = game:GetService('ReplicatedStorage')
local remotesFolder = replicatedStorage:WaitForChild('Remotes')
local unreliableUpdateLocation = remotesFolder:WaitForChild('UnUpdateLocation')

local UpdateLocation = function(vectorPos)
	local lerp = char.PrimaryPart.Position:Lerp(vectorPos, .5)
end

local HeartBeat = function(dt)
	local target = Vector3.new(mouse.Hit.X, char.PrimaryPart.Position.Y, mouse.Hit.Z)
	tween:Create(char.PrimaryPart, info, {CFrame = CFrame.lookAt(char.PrimaryPart.Position, target)}):Play()

	linear.VectorVelocity = char.PrimaryPart.CFrame.LookVector * moveSpeed 
end

unreliableUpdateLocation.OnClientEvent:Connect(UpdateLocation)
runService.Heartbeat:Connect(HeartBeat)

"EDIT: The RedPart is simulating where the server sees the player at. I want the player to go to the RedPart position (where server sees it)

I tried to make a video with server, and 2 client perspectives but wasn’t able to (Due to FPS). Imagine that:

Server: Player1 and Player2 are at position 5
Client Player1: Player2 is at position 4 or 5, I am at position 6
Client Player2: Player1 is at position 4 or 5, I am at position 6

While server sees them paired with each other, the P1 sees himself in front of P2 and P2 sees himself in front of P1"

2 Likes

Use physics bodyforces to move the block.
Let each player control their block locally by giving them network ownership over it.

This makes it look perfect for the player itself. Server will still see a different position for the blocks. Usually lagging behind the player position due to ping.

All the server has to do is create a block per player and give them network ownership. Each client handles their own block individually.

3 Likes

“Ty for replying, Im going to take a look at bodyforces but I don’t understand how this could help me with my problem”

The White Block is the player, so client already has network ownership right? The RedPart is simulating where the server sees the player at. I want the player to go to the RedPart position (where server sees it)

I tried to make a video with server, and 2 client perspectives but wasn’t able to (Due to FPS). Imagine that:

Server: Player1 and Player2 are at position 5
Client Player1: Player2 is at position 4 or 5, I am at position 6
Client Player2: Player1 is at position 4 or 5, I am at position 6

While server sees them paired with each other, the P1 sees himself in front of P2 and P2 sees himself in front of P1

1 Like

You want players to be ‘corrected’ in their position?

Server-authoritative movement?
If yes, then I recommend chikynoid.

“chikynoid Is actually going to be one of my tries”

This vídeo would probably resume my problem

Minute 6:00 to 7:15

“Btw sorry If my problem and anwers doesn’t make much sense, I’ve been lost in this matter for quite a bit of time”

1 Like

I solved my problem thx for everyone. I realized I was just being dumb using interpolation to force the player position to the server position or extrapolation to force the server position to the player position, but that isn’t necessary since I can “fake it” just make so my client extrapolates the other players position and vice versa.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.