Clientisde prediction in SetVelocity?

So, the last week or so I’ve been experimenting with lua and learning about it with friends. I’ve given the wikis a good spin, both the official and deprecated ones. While success has followed in the meanwhile, I still have somewhat of an unclear idea if setting velocity to the player through a script can be predicted clientside. As far as my research goes, none of the wikis go over predicting velocity changes, just basic movement changes. So the basic idea behind getting this to work is so scripted velocity changes can feel smooth for the client, and not result in a sudden warp which can result in disorienting the player and making it difficult to interpolate actions. So would it be possible to predict something like this?

Setting the velocity shared will mostly smooth this out. If you don’t set it clientside, trying to retrieve the velocity will cause it to be estimated until the client is updated with the correct value.

I’ve experimented with this a bit, but the results are nothing short of just setting the velocity purely serverside. I have tried doing this in both a shared script, and seperate client/server scripts, but the outcome is the player not being updated with the velocity, causing a sudden warp. I’ve even tried using shared, and predicted hooks, but it didn’t change much. Am I doing something wrong?

Can you give specific code instances?

It could be that you’re using a non networked variable to tell the player to start doing the predicted velocity, which could mean that clientside it’s never doing it even when your code is shared.

Just in case we’re on the same page here, here’s an example of setvelocity working shared 100% even with high ping.

hook.Add( “Move” , “PredictionTest” , function( ply , mv )

if mv:KeyDown( IN_SPEED ) then
	local sinewave = math.abs( math.sin( CurTime() ) )
	local speed = 1000
	mv:SetVelocity( ply:GetAimVector() * sinewave * speed )
	ply:SetGroundEntity( NULL )


Aim at the sky while holding sprint and the player will fly with a varying speed.