Basically, these functions are called from my Player's [Replicate] method :
public override void LogicUpdate(PlayerRunInputs md, ReplicateState state)
{
base.LogicUpdate(md);
if (state == ReplicateState.CurrentCreated)
FireProjectile(md.AimDirectionInput, state);
}
public void FireProjectile(Vector2 aimDirection, ReplicateState state)
{
Vector2 force = aimDirection * pC.playerMovementConfig.fireForce;
Vector3 aimDirection = force.normalized;
float spawnDistance = 1.0f; // Distance from the player's center to spawn the projectile
Vector3 spawnOffset = aimDirection * spawnDistance;
Vector3 spawnPosition = transform.position + spawnOffset;
float angle = Mathf.Atan2(force.y, force.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
NetworkObject nob =
InstanceFinder.NetworkManager.GetPooledInstantiated(_projectilePrefab, spawnPosition, rotation, true);
if (!nob)
{
Debug.LogError("Projectile prefab is not cached.");
return;
}
BasicRigidbodySync brs = nob.GetComponent<BasicRigidbodySync>();
if (!brs)
{
Debug.LogError("Projectile prefab does not have a BasicRigidbodySync component.");
return;
}
//Spawning the CSP projectile
InstanceFinder.NetworkManager.ServerManager.Spawn(nob, Owner);
brs.force = force;
}