#trying to do that but it does nothing

1 messages · Page 1 of 1 (latest)

normal ore
#

post the code for your server RPC here. That should work

fresh shoal
#

this is my rpc

    public void RotatePlayerServerRPC(Quaternion rotation)
    {
        transform.rotation = rotation;
    }```
normal ore
#

MouseX is a float not a Quaternion.
You need to do playerBody.Rotate(Vector3.up * MouseX); on the server

fresh shoal
#

and here is my mouse script

    NetworkCommunication networkCommunication;
    public Transform playerBody;
    float xRotation = 0f;

    void Start()
    {
        networkCommunication = GetComponentInParent<NetworkCommunication>();
    }

    void Update()
    {
        float MouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
        float MouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

        xRotation -= MouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);
        

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * MouseX);
        networkCommunication.RotatePlayerServerRPC(playerBody.rotation);
    }```
#

so i should make an rpc like :
PlayerRotateServerRPC(Vector3.up * MouseX) ?

#

who will my server know which playerBody to move ?

normal ore
#

Is this script not on the player?

fresh shoal
#

it's on the player

normal ore
#

Then that is the player body that will move. As long as the server has a reference to playerBody

fresh shoal
#

ok it "works" not having that weird shake effect juste the mouse sensitivity a bit slow but it can be modify

#

and having a last issue for today

#

so here is the probleme :
in this RPC when an other client try to call it the rotation of the shot is my host rotation like it takes the rotation of the host and i don't know why

    public void CreateBulletServerRpc()
    {
        if (isShootingRange) 
        {
            Vector3 dispersion = new Vector3(Random.Range(-weaponDispersion, weaponDispersion), Random.Range(-weaponDispersion, weaponDispersion), Random.Range(-weaponDispersion, weaponDispersion));
            GameObject bullet = Instantiate(bulletPrefab, transform.position, transform.rotation);
            bullet.GetComponent<Rigidbody>().AddForce((transform.forward + dispersion).normalized * weaponSpeedBalisitic);
            bullet.AddComponent<BulletScript>();
        }
        else
        {
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)), out hit, 100f))
            {
                Vector3 dispersion = new Vector3(Random.Range(-weaponDispersion, weaponDispersion), Random.Range(-weaponDispersion, weaponDispersion), Random.Range(-weaponDispersion, weaponDispersion));
                GameObject bullet = Instantiate(bulletPrefab, gameObject.GetComponentInChildren<WeaponParts>().weaponMuzzle.transform.position, weaponSpawner.transform.rotation);
                bullet.GetComponent<NetworkObject>().Spawn();
                bullet.GetComponent<BulletScript>().bulletSpeed.Value = weaponSpeedBalisitic;
                bullet.GetComponent<BulletScript>().direction.Value = (hit.point + dispersion - gameObject.GetComponentInChildren<WeaponParts>().weaponMuzzle.transform.position).normalized;
                
            }
            else 
            {
                Vector3 dispersion = new Vector3(Random.Range(-weaponDispersion, weaponDispersion), Random.Range(-weaponDispersion, weaponDispersion), Random.Range(-weaponDispersion, weaponDispersion));
                GameObject bullet = Instantiate(bulletPrefab, gameObject.GetComponentInChildren<WeaponParts>().weaponMuzzle.transform.position, weaponSpawner.transform.rotation);
                bullet.GetComponent<NetworkObject>().Spawn();
                bullet.GetComponent<BulletScript>().bulletSpeed.Value = weaponSpeedBalisitic;
                bullet.GetComponent<BulletScript>().direction.Value = (Camera.main.transform.forward + dispersion).normalized;
            }
        } 
    }
#

should i put my rotation as param ?

normal ore
#

I think so. depends on where this script is located

fresh shoal
#

the script is located on my player

normal ore
#

does the weapon muzzle have a network transform?

fresh shoal
#

no it doesn't

normal ore
#

it will probably need one so its position can get synced

fresh shoal
#

ohh maybe it's due to my network variables ?

#
    public NetworkVariable<Vector3> direction = new NetworkVariable<Vector3>();

    public override void OnNetworkSpawn()
    {
        base.OnNetworkSpawn();
    }

    void OnCollisionEnter(Collision other)
    {
        if (bulletImpact != null)
        {
            GameObject bulletImpactInstance = Instantiate(bulletImpact, transform.position, transform.rotation);
            Destroy(gameObject);
            Destroy(bulletImpactInstance, 2);
        }
    }

    void Start() 
    {
        GetComponent<Rigidbody>().AddForce(direction.Value * bulletSpeed.Value);
    }``` which is not attached to my player but my bullet
normal ore
fresh shoal
#

ohhh i see i need to take the camera of the player

normal ore
#

you can actually send a Ray as a parameter if you want

fresh shoal
#

ohhh that's nice i will try it tomorrow

#

thank's a lot

fresh shoal
#

it works thank you !