#Is it possible to trigger OnTriggerStay function but only on Server?

1 messages · Page 1 of 1 (latest)

warped plover
#

title

foggy stone
warped plover
warped plover
#

actually... i don't understand something obviously :S

#
using UnityEngine;
using Mirror;

public class BallDetection : MonoBehaviour
{
    private Rigidbody _rigidbody;

    private void Awake()
    {
        _rigidbody = GetComponentInParent<Rigidbody>();
    }

    [ServerCallback]
    private void OnTriggerStay(Collider other)
    {
        if (!other.CompareTag("Player")) return;

        Vector3 pushDir = (transform.position - other.transform.position).normalized;
        _rigidbody.AddForce(pushDir * 1f, ForceMode.Impulse);
    }
}

#

I have this script on a sphere object,
and it has collision enabled and when a Player collides with it, I want it to move,
but now it only works when server does it

#

why it doesn't work with other clients?

sacred garnet
#

use

#if UNITY_SERVER

// YOUR CODE

#endif

this way this code won't even be compiled in client

warped plover
#

that is the same as [Server] right?

cobalt reef
#

That's for server builds

#

The server callback makes any function run on the server only