- Home /
[Photon] Shoot Projectile multiplayer to mousePos
Hello!
I am currently using Photon Engine to my multiplayer game. I want to shoot projectile in the direction of my crosshair, but when I do fireball at Client 1 goes there where it should, but in the client 2 (the one who didnt fire the fireball, only watches the fireball of client 1) it goes in the direction of his camera, not direction of "shoot owner"'s camera.
Ray ray = MainCamera.ScreenPointToRay (tmCursor.position);
Vector3 shootPos = new Vector3 (ray.direction.x, ray.direction.y, ray.direction.z);
bullet.velocity = shootPos * speed;
I gave camera Photon View and Photon Transform but it idn't give anything... What should I do? Thanks in advance for your help.
Firstly, make sure there's only ONE camera at all times on the local client. When the player spawns (make sure the camera gameobject is disabled in the prefab) turn on the camera gameobject, this will make it so the camera is only enabled for the local player and not other players. For example:
GameObject player = (GameObject)PhotonNetwork.Instantiate(playerGO, Vector3.zero, Quaternion.identity);
player.transform.FindChild("$$anonymous$$ain Camera").gameObject.SetActive(true);
The only thing I can think of is that there's 2 cameras in the scene and they're both $$anonymous$$ainCameras, thus leading to this issue.
I have a camera already placed in the scene, I do not instantiate it with a player prefab. Should I do it differently?
The point is that when I shoot my projectile in direction of cursor from client1, in the client2 this projectille goes in the direction of cursor from client2, and it should go in the direction of cursor from client 1.
[PunRPC]
public void Shoot(){
$$anonymous$$ainCamera = Camera.main;
Ray ray = $$anonymous$$ainCamera.ScreenPointToRay (tmCursor.position);
Vector3 shootPos = new Vector3 (ray.direction.x, ray.direction.y, ray.direction.z);
bullet.velocity = shootPos * speed;
bullet.setActive(true);
}
void Update () {
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0)&& ctPhotonView.is$$anonymous$$ine ){
ctPhotonView.RPC("Shoot",PhotonTargets.All);
}
}
Your answer
Follow this Question
Related Questions
Bullet Collision in Networking Game. 0 Answers
Photon Player Controls Other Player 0 Answers
Use MasterClient as Authoritative server (Latency Issue) 2 Answers
Photon network won't join random room with a custom property 0 Answers
Shooting projectiles in a 2d top down shooter with multiplayer 1 Answer