- Home /
Question by
Yehudy85 · Apr 22, 2021 at 09:08 PM ·
1st person
Problems Multiplayer Game with MLAPI - Enemy move delay on Client
Hello community ... I need your help. I am creating a simple 2d multiplayer game. First use mirror and create an object (EnemySpawner) that is responsible for generating enemies randomly, the enemies move from top to bottom, using mirror everything works fine on client side. But then I decided to use mlapi, when I run the game as a server the movement of the enemies is fluid but when entering as a client the movement of the enemies has a delay. Thanks for the help you can give me. This is my code that generates enemies:
[SerializeField]
private GameObject enemyPrefab;
[SerializeField]
private float spawnInterval = 1.0f;
[SerializeField]
private float enemySpeed = 1.0f;
public override void NetworkStart ()
{
if (IsServer)
InvokeRepeating ("SpawnEnemy", this.spawnInterval, this.spawnInterval);
}
void SpawnEnemy ()
{
Vector2 spawnPosition = new Vector2 (Random.Range (-7.0f, 7.0f), this.transform.position.y);
enemy = Instantiate (enemyPrefab, spawnPosition, Quaternion.identity);
enemy.GetComponent <Rigidbody2D> () .velocity = new Vector2 (0.0f, -this.enemySpeed);
enemy.GetComponent <NetworkObject> () .Spawn ();
Destroy (enemy, 10);
}
Comment