#Movement issue

5 messages · Page 1 of 1 (latest)

harsh pollen
#

` private ReplicateData CreateReplicateData()
{
if (!base.IsOwner)
return default;

    //Build the replicate data with all inputs which affect the prediction.
    Vector2 movementNorm = GameInput.Instance.GetMovementVectorNormalized();

    Vector3 forward = cameraController.GetCameraForward();
    bool onSlope = SlopeCheck();
  
    Debug.Log(
        $"flatVel {PredictionRigidbody.Rigidbody.velocity.magnitude:F2} ClientId-{Owner.ClientId}"
    );
    ReplicateData md = new ReplicateData(
        _jump,
        movementNorm,
        forward,
        _isGrounded,
        onSlope,
        _slopeHit.normal,
        SpeedEffect.Instance.isSpeedEffectActive
    );
    _jump = false;

    return md;
}

`

#

`
[Replicate]
private void RunInputs(
ReplicateData data,
ReplicateState state = ReplicateState.Invalid,
Channel channel = Channel.Unreliable
)
{
TraceAndSetParent();

    if (data.IsGrounded)
    {
        PredictionRigidbody.Rigidbody.drag = 5;
    }
    else
    {
        PredictionRigidbody.Rigidbody.drag = 0;
    }

    Vector3 forward = data.Forward;

    forward.y = 0;
    forward.Normalize();

    Vector3 movementDirection =
        forward * data.MovementNorm.y
        + Vector3.Cross(Vector3.up, forward) * data.MovementNorm.x;

    float currentMaxSpeed = data.IsRunning ? _runSpeed : _moveSpeed;
    Vector3 targetVelocity;

    if (data.OnSlope)
    {
        targetVelocity =
            GetSlopeMoveDirection(movementDirection.normalized, data.SlopeHitNormal)
            * currentMaxSpeed;
    }
    else
    {
        targetVelocity = movementDirection.normalized * currentMaxSpeed;
    }

    PredictionRigidbody.Velocity(
        new Vector3(
            targetVelocity.x,
            PredictionRigidbody.Rigidbody.velocity.y,
            targetVelocity.z
        )
    );

    Vector3 flatVel = new Vector3(
        PredictionRigidbody.Rigidbody.velocity.x,
        0f,
        PredictionRigidbody.Rigidbody.velocity.z
    );
   

    if (flatVel.magnitude > currentMaxSpeed)
    {
        Vector3 limitedVel = flatVel.normalized * currentMaxSpeed;
        PredictionRigidbody.Velocity(
            new Vector3(limitedVel.x, PredictionRigidbody.Rigidbody.velocity.y, limitedVel.z)
        );
    }

    PredictionRigidbody.Simulate();
}`
#

When i moving from client perspective velocity is similar (for player1(host), and player2), but when i do the same from host player, values differ

harsh pollen
#

@boreal venture