Ejemplo n.º 1
0
    static void OnClientVehiclePosMsg(NetworkMessage message)
    {
        VehiclePosMessage msg = message.ReadMessage <VehiclePosMessage>();

        if (msg == null)
        {
            return;
        }

        PlayerMessager messager = messagers.Find((m) => { return(m.netId == msg.netId); });

        if (messager != null && !messager.isLocalPlayer && msg.number > messager.lastNumber)
        {
            messager.lastNumber = msg.number;

            messager.lerpValue = 0;

            messager.lastPos = messager.transform.position;
            messager.lastRot = messager.transform.rotation;

            messager.targetPos = msg.pos;
            messager.targetRot = msg.rot;

            // messager.rigidbody.velocity = msg.velocity;
            // messager.rigidbody.angularVelocity = msg.angularVelocity;
            messager.vehicle.steering = msg.steering;
            messager.vehicle.throttle = msg.throttle;
            messager.vehicle.boosting = msg.boosting;
            messager.vehicle.drift    = msg.drifting;
        }
        else if (messager == null)
        {
            Debug.LogWarning("Could not find target");
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (isLocalPlayer && (Time.realtimeSinceStartup - lastSync >= 1 / updateRate || player.collisionDetected))
        {
            lastSync = Time.realtimeSinceStartup;

            VehiclePosMessage msg = new VehiclePosMessage();
            msg.number          = messageCount++;
            msg.netId           = netId;
            msg.pos             = transform.position;
            msg.rot             = transform.rotation;
            msg.velocity        = rigidbody.velocity;
            msg.angularVelocity = rigidbody.angularVelocity;
            msg.steering        = vehicle.steering;
            msg.throttle        = vehicle.throttle;
            msg.boosting        = vehicle.boosting;
            msg.drifting        = vehicle.drift;
            msg.collision       = player.collisionDetected;

            connectionToServer.SendByChannel(NetworkMessages.PlayerUpdatePos, msg, 1);

            player.collisionDetected = false;
        }
        else if (!isLocalPlayer && lerpValue <= 1f)
        {
            lerpValue += Time.deltaTime * updateRate;

            transform.position = Vector3.Lerp(lastPos, targetPos, lerpValue);
            transform.rotation = Quaternion.Lerp(lastRot, targetRot, lerpValue);
        }
    }
Ejemplo n.º 3
0
    static void OnServerVehiclePosMsg(NetworkMessage message)
    {
        VehiclePosMessage msg = message.ReadMessage <VehiclePosMessage>();

        if (msg == null)
        {
            return;
        }

        NetworkServer.SendUnreliableToAll(NetworkMessages.PlayerUpdatePos, msg);
    }