Hi guys, I’m trying to do a camera that will make it possible to follow a player based on his network ID. So if you log into the game and don’t choose any vehicule, you’ll be able to follow a certain player.
Any ideas on the best way to achieve this ?
I’d create a Dictionary, mapping the Player objects to the players ID.
Then you could just set the target of a regular camera follow script to what you get out of the Dictionary when throwing in the ID.
Of course, you need to maintain the Dictionary contents by adding and removing entries on Network Events.
Thanks for the reply. But it seenms that I can’t find the GameObject of the connected player with :
GameObject Vehicule = GameObject.Find("Player");
Network.Instantiate(BackCam, Vehicule.transform.position, Vehicule.transform.rotation, TestGroup);
I tried to replace the name of the object “Player” for “Player(Clone)” (as it shows up in hierarchy) but got a null value either way.
There is no reason to use GameObject.Find at any time.
I never use it since object names is nothing you should ever rely on.
And: Why would you instantiate the camera over Network? A camera is something you handle locally.
Also, this hasn’t much to do with your initial post, has it?
I’m making a car simulator wich has 6 screens. 3 for the front and 3 for the back view. I’m using 2 computer to render the visuals. So I need to attach a camera over the network to the “Player” that has the front view to make a back view that follow correctly.
Not exactly. You can as well synchronize the car and let the cameras follow locally. The result should be the same, let aside the decreased network overhead.
Interesting. What should I do to synchronize the car ? Adjust the Network View’s synchronisation ? Sorry for my lack of knowledge but we just switched to Unity so I’m learning it as I built the simulator.
Well, you have to synchronize the car anyway since all players should see it at the right position at any given time, right?
You do that in any manner you like.
The question just is wether or not the camera should be synchronized too, and I’d say no to that, since it’s position is calculated with the same algorithm (same script) and the same data (car position) for all players. So you can save bandwith and increase performance by just syncing the car and let the clients extrapolate that data to get the same camera position.
It’s like sending a math question (5+5=?) to someone’s computer for them to solve, and whether or not you send the answer (10) to them or let their computer calculate it to validate the answer.
Well my cars are synced correctly, but I don’t understand how to retrieve the position of one of them in my script to attach a cam.
Feeling dumb really.
Simply use a regular Camera Follow script that you’d use in a regular singleplayer game.
It works locally and doesn’t even bother doing networking.