Tank trails don't sync in multiplayer

The tag system doesn’t seem to work for this lecture so this is about video 12_OM_UMP “Making Trails”

They seem to work perfectly when driving around on your own but when playing with others the other players tracks only show up once every few ticks.
Not sure if anyone else has this issue as well?

Sorry, this post got lost, our post tagging system is having issues. Were you able to resolve this issue? Any ideas @Marc_Carlyon ?

I think this one also popped up on Udemy and the student did not get back to me after checking their code.
I never did get what they did to fix it but i assume something is in the incorrect place.

I didn’t, the dustCloud seems to be syncing just fine so I don’t get why the tracks trails do not.

Can you post the associated scripts and also try to recreate the trails and see if it might be an issue with the particle system lifetime or something like that.

Thanks in advance and let me know on this (I have fixed the tagging manually so hopefully it wont be an issue in the future!)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(ParticleSystem))]
public class ParticleAligner : MonoBehaviour
{
    private ParticleSystem.MainModule psMain;
    private void Start()
    {
        psMain = GetComponent<ParticleSystem>().main;
    }

    private void Update()
    {
        psMain.startRotation = -transform.rotation.eulerAngles.z * Mathf.Deg2Rad;
    }
}

Schermafbeelding 2023-07-31 222730
This is what my tracks look like while playing.

Schermafbeelding 2023-07-31 222703
This is what the other clients tracks look like for me while playing.

And I don’t think the issue lays with the particle system, but rather by the way it’s being synced between clients.

Hi,

Your particle aligner is fine but could you post the movement script.
I agree that its unlikely its the particle system as if it was then it would be causing the issue locally not just over the network.
I also agree with its very confusing as you would expect the smoke trail to be a similar issue being as they are using the same script just not being aligned.

Just for sanity check sake can you let me know the version of unity being used and the version of the netcode for games package being used.

I will try to check in tomorrow on this as i noticed your question late in the evening so may not get your reply until tomorrow.

We will keep on this until we find out whats causing this but i want to rule out anything at the project side really before starting to see if its a bug thats in unity (Much like the UI bug that pops up)

using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;

public class PlayerMovement : NetworkBehaviour
{
    [Header("References")]
    [SerializeField] private InputReader inputReader;
    [SerializeField] private Transform bodyTransform;
    [SerializeField] private Rigidbody2D rb;
    [SerializeField] private ParticleSystem dustCloud;
    [SerializeField] private AudioSource tankMovementAudio;


    [Header("Settings")]
    [SerializeField] private float movementSpeed = 4f;
    [SerializeField] private float turningRate = 30f;
    [SerializeField] private float particleEmissionValue = 10;

    private ParticleSystem.EmissionModule emissionModule;
    private Vector2 previousMovementInput;
    private Vector3 previousPos;

    private const float ParticleStopTreshold = 0.005f;

    private void Awake()
    {
        emissionModule = dustCloud.emission;
    }
    override public void OnNetworkSpawn()
    {
        if (!IsOwner)
        {
            return;
        }
        inputReader.MoveEvent += HandleMove;
    }

    public override void OnNetworkDespawn()
    {
        if (!IsOwner)
        {
            return;
        }
        inputReader.MoveEvent -= HandleMove;
    }

    void Update()
    {
        if (!IsOwner)
        {
            return;
        }
        float zRotation  = previousMovementInput.x * -turningRate * Time.deltaTime;
        bodyTransform.Rotate(0f, 0f, zRotation);
    }
    private void FixedUpdate()
    {
        if((transform.position - previousPos).sqrMagnitude > ParticleStopTreshold)
        {
            emissionModule.rateOverTime = particleEmissionValue;

            tankMovementAudio.pitch = 1f;
        }
        else
        {
            emissionModule.rateOverTime = 0;

            tankMovementAudio.pitch = 0.90f;
        }

        previousPos = transform.position;

        if (!IsOwner)
        {
            return;
        }
        rb.velocity = (Vector2)bodyTransform.up * previousMovementInput.y * movementSpeed;
    }

    private void HandleMove(Vector2 movementInput)
    {
        previousMovementInput = movementInput;
    }
}

And I’m using Unity 2022.3.5f1
Netcode For GameObjects is at 1.5.1 (But I see that 1.5.2 has become available.)

And thanks for the replies :slight_smile:

@Yitzchak_Cohen Have you got any ideas on this one as to be honest its got me a little stumped at the moment.

Are you able to see if enough particles are being spawned for the other client’s tracks on your client? I guess I am wondering if the issue is there aren’t enough tracks or if their position is incorrect.

Hi @Thimoca,
I eventually ran into this issue myself. I solved it by making a small change to the particle systems.
image
I changed the emitter velocity mode from rigidbody to transform.

1 Like

That did solve the issue, thanks :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms