I’m working on physics-based multiplayer game and I need to have an actor like tower crane - 3 physical body with 2 constraints.
With a classic options when server does all the physics the controls on client side feels bad - delay and jitters. I’m trying now to do that using network physics component.
I tested it on a simple actor based on this example:
And this seems to work okay. However when I’m trying to apply that to a more complex system, I see that the result is producing, but it looks exactly the same as server authoritieve option, so I guess it’s not applied correclty.
This is a short example of my code, not everything but to give an idea of what I’m doing:
USTRUCT()
struct FCraneInputs
{
GENERATED_BODY()
FCraneInputs()
: SteeringInput(0.f)
, HookMovement(FVector::ZeroVector)
{
}
// Steering output to physics system. Range -1...1
UPROPERTY()
float SteeringInput;
// Desired direction
UPROPERTY()
FVector HookMovement;
};
void UCraneMovementComponent::AsyncPhysicsTickComponent(float DeltaTime, float SimTime)
{
Super::AsyncPhysicsTickComponent(DeltaTime, SimTime);
if (!TowerBodyInstance || !UpdatedConstraint)
{
return;
}
// Apply torque to rotate the tower
if (const auto Handle = TowerBodyInstance->ActorHandle)
{
HandleTower = Handle->GetPhysicsThreadAPI();
if (HandleTower)
{
HandleTower->AddTorque(FVector(0, 0, CraneInputs.SteeringInput * 10000000000));
}
// Change the constraint (not sure it's safe to do this way in physics thread)
if (UpdatedConstraint)
{
UpdatedConstraint->SetLinearPositionTarget(CraneInputs.HookMovement);
}


