I got confused for a bit why we where sending the velocity to the movement component, when the movement component isn’t simulating moves as a SimulatedProxy.
It’s just where we are storing it, we grab it again in SimulatedProxy_OnRep_ServerState() for using as the start velocity in the cubic lerp. The movement comp doesn’t care about it.
@Maysh i think you’re totally right
It seems that this line (GoKartMovementComponent->SetVelocity(Velocity)) is redundant since it sets the velocity value on the GoKartMovementComponent, but the GoKartMovementComponent is not simulating moves for the SimulatedProxy so there is no meaning of setting this velocity value, And therefore all the logic behind making the Hermite cubic spline for direvatives is also redundant.
@sampattuzzi what does the course stuff think about it?
It’s been a while since I wrote the code! It’s quite possible that I’m just storing the velocity as Maysh says.
I was also wondering about this and did some testing.
In actuality, removing MovementComponent->SetVelocity(NewVelocity)
from ClientTick
results in the Simulated proxy vehicle looking much more staggered in its movement, appearing as though it’s using an EaseInEaseOut interpolation. So it moves fastest halfway between the server update locations, but when leaving/approaching the points it’s interpolating to/from, it seems to come to a complete stop.
The reason I believe setting the Velocity is necessary is due to us using ClientStartVelocity
to get the StartDerivative
which is used to calculate NewLocation
. With that in mind, I tried removing
ClientStartLocation = MovementComponent->GetVelocity()
from
SimulatedProxy_OnRep_ServerState
and removing
MovementComponent->SetVelocity(NextVelocity);
from
ClientTick
in favor of just setting ClientStartVelocity = NewVelocity
directly after it’s calculated. However this resulted in some very bizarre behavior where the Z value of NewDerivative
occasionally slips downward after the first ClientTick
and exponentially increases (or decreases since it’s negative) causing the SimulatedProxy vehicle to appear to go into the floor and disappear forever.
See Log:
LogTemp: Warning: SimulatedProxy_OnRep_ServerState. UpdatedClientLocation: X=710.000 Y=9500.000 Z=202.000
LogTemp: Warning: VelocityToDerivative: 5.015190
LogTemp: Warning: NewLocation: X=710.000 Y=9500.000 Z=202.000
LogTemp: Warning: NewDerivative: X=0.000 Y=0.000 Z=-0.000
LogTemp: Warning: NewVelocity: X=0.000 Y=0.000 Z=-0.000
LogTemp: Warning: VelocityToDerivative: 5.015190
LogTemp: Warning: NewLocation: X=710.000 Y=9500.000 Z=201.999
LogTemp: Warning: NewDerivative: X=0.000 Y=0.000 Z=-0.002
LogTemp: Warning: NewVelocity: X=0.000 Y=0.000 Z=-0.000
LogTemp: Warning: VelocityToDerivative: 5.015190
LogTemp: Warning: NewLocation: X=710.000 Y=9500.000 Z=201.977
LogTemp: Warning: NewDerivative: X=0.000 Y=0.000 Z=-0.031
LogTemp: Warning: NewVelocity: X=0.000 Y=0.000 Z=-0.006
LogTemp: Warning: VelocityToDerivative: 5.015190
LogTemp: Warning: NewLocation: X=710.000 Y=9500.000 Z=200.882
LogTemp: Warning: NewDerivative: X=0.000 Y=0.000 Z=-1.022
LogTemp: Warning: NewVelocity: X=0.000 Y=0.000 Z=-0.204
LogTemp: Warning: VelocityToDerivative: 5.015190
LogTemp: Warning: NewLocation: X=710.000 Y=9500.000 Z=119.663
LogTemp: Warning: NewDerivative: X=0.000 Y=0.000 Z=-57.500
LogTemp: Warning: NewVelocity: X=0.000 Y=0.000 Z=-11.465
LogTemp: Warning: VelocityToDerivative: 5.015190
LogTemp: Warning: NewLocation: X=710.000 Y=9500.000 Z=-8479.286
LogTemp: Warning: NewDerivative: X=0.000 Y=0.000 Z=-4908.687
LogTemp: Warning: NewVelocity: X=0.000 Y=0.000 Z=-978.764
LogTemp: Warning: VelocityToDerivative: 5.015190
LogTemp: Warning: NewLocation: X=710.000 Y=9500.000 Z=-1246674.640
LogTemp: Warning: NewDerivative: X=0.000 Y=0.000 Z=-592169.323
LogTemp: Warning: NewVelocity: X=0.000 Y=0.000 Z=-118075.149
LogTemp: Warning: VelocityToDerivative: 5.015190
LogTemp: Warning: NewLocation: X=710.000 Y=9500.000 Z=-233484998.457
LogTemp: Warning: NewDerivative: X=0.000 Y=0.000 Z=-95709158.994
LogTemp: Warning: NewVelocity: X=0.000 Y=0.000 Z=-19083854.573
I’m not entirely sure what the cause of this is (might be due to the engine trying to adjust spawn location?) but it’s amplified by the fact that the ClientTick
is happening every frame whereas SimulatedProxy_OnRep_ServerState
only runs as many times as NetUpdateFrequency
allows for (so once a second if using the same values as @sampattuzzi).
Tl;dr
Setting Velocity on the MovementComponent
is really just a way of caching the ClientStartVelocity
on every SimulatedProxy update and using that value to calculate StartDerivative
(and thus NewLocation
). It could also be done by having another float on the Replicator component that only updates ClientStartVelocity
once every SimulatedProxy update, but we already have the value on the Movement Component so…
Side note, I also realized the reason the client vehicle sometimes wouldn’t spawn is because the ‘Spawn Collision Handling Method’ is set to “Try to Adjust Location, Don’t Spawn if Still Colliding” by default on our BP_GoKart (No clue why since I believe the normal default is Always Spawn?) So if you want to fix it, just change the value to “Try to Adjust Location, But Always Spawn” (you may also want to change the value on the PlayerStarts in the map). This does pose the potential problem of the client vehicle spawning at the same point as the server vehicle, which is very strange and I’ve never seen happen if there’s multiple PlayerStarts so maybe there’s some strange default project settings? Idk