#trying to do that but it does nothing
1 messages · Page 1 of 1 (latest)
this is my rpc
public void RotatePlayerServerRPC(Quaternion rotation)
{
transform.rotation = rotation;
}```
MouseX is a float not a Quaternion.
You need to do playerBody.Rotate(Vector3.up * MouseX); on the server
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 ?
Is this script not on the player?
it's on the player
Then that is the player body that will move. As long as the server has a reference to playerBody
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 ?
I think so. depends on where this script is located
the script is located on my player
does the weapon muzzle have a network transform?
no it doesn't
it will probably need one so its position can get synced
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
also the Camera you are doing the Raycast from is the host camera
ohhh i see i need to take the camera of the player
you can actually send a Ray as a parameter if you want
it works thank you !