- Home /
Question by
TheLittleJungler · Sep 02, 2021 at 12:21 PM ·
c#networkingphotonraycastingprojectile
Photon Unity Networking - Projectile Syncing problem
So, im developing a multiplayer shooting game but i stumbled upon a problem that i cannot fix. My problem is that the projectile owner can see it going perfectily to the point the camera is facing but the other players can only see it going to a never changing fixed point on the map (forward).
public class FastWand : Wand
{
[SerializeField] Camera cam;
[SerializeField] Transform atackPoint;
[SerializeField] GameObject projectile;
[SerializeField] float projectileSpeed = 30.0f;
private Vector3 destination;
PhotonView PV;
public float arcRange = 1;
private void Awake()
{
PV = GetComponent<PhotonView>();
}
public override void Use()
{
Shoot();
}
void Shoot()
{
Ray ray = cam.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
ray.origin = atackPoint.position;
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log(hit);
hit.collider.gameObject.GetComponent<IDamageable>()?.TakeDamage(((WandInfo)itemInfo).damage);
destination = hit.point;
PV.RPC("RPC_Shoot", RpcTarget.All);
print("I'm looking at " + hit.transform.name);
print("Destination " + destination);
}
else
{
Debug.Log(hit);
destination = ray.GetPoint(1000);
PV.RPC("RPC_Shoot", RpcTarget.All);
print("I'm looking at Void");
}
}
[PunRPC]
void RPC_Shoot()
{
var projectileObj = Instantiate(projectile, atackPoint.position, atackPoint.rotation/*Quaternion.identity*/) as GameObject;
projectileObj.GetComponent<Rigidbody>().velocity = (destination - atackPoint.position).normalized * projectileSpeed;
iTween.PunchPosition(projectileObj, new Vector3(Random.Range(-arcRange, arcRange), Random.Range(-arcRange, arcRange), 0), Random.Range(0.5f, 2));
Destroy(projectileObj, 5);
}
}
Comment
Your answer
Follow this Question
Related Questions
Unity Photon Network - Text Mesh Sync 1 Answer
Sync Projectile Shooting with Photon Networking 0 Answers
Photon Unity Networking Score Issue 1 Answer
Multiple Cars not working 1 Answer
Problems with Photon self-hosted server 0 Answers