Currently i am trying to add knockback to my predicted CC. when a projectile hits a target "AddKnockback" is called locally to allow clients to predict knockback, knockback is used inside Replicate (RunInputs) to add to the character movement.
The problem is, at the moment the client does not see knockbacks and instead is reconciled to the servers position and only plays the end of the knockback effect.
ill include a video and the code. if anyone has any ideas please let me know, been struggling with this for a few days.
Onhit function (this is on a predicted projectile)
private void OnTriggerEnter(Collider other)
{
if (other.gameObject == _owner.playerStats.gameObject) { return; }
if (InstanceFinder.IsClientStarted)
{
//If client show visual effects, play impact audio.
Instantiate(hitVfx, transform.position, transform.rotation);
PlayerPredictedMovement victimMovement = other.gameObject.GetComponent<PlayerPredictedMovement>();
if(victimMovement != null) { victimMovement.AddKnockback(.17f, transform.position); }
}
if (InstanceFinder.IsServerStarted)
{
PlayerStats victim = other.gameObject.GetComponent<PlayerStats>();
if (victim != null)
{
victim.TakeDamage(1);
// PlayerPredictedMovement victimMovement = other.gameObject.GetComponent<PlayerPredictedMovement>();
// if (victimMovement != null) { victimMovement.AddKnockback(.17f, transform.position); }
}
else { Debug.Log("No victim found" + other.gameObject); }
}
Destroy(gameObject);
}
