I created a multiplayer game with photon in unity. The player is a rolling ball, i want to set a camera for each player but it can't be a child of the ball otherwise it rotates to. Without photon it worked with a script on the camera but now with the multiplayer the camera doesn't follow the rolling ball. How can i fix it?
Asked
Active
Viewed 1,168 times
0
-
What you can do instead, to make it easier, is split the ball in to two objects. An empty parent object that you move to control position, you would attach your camera/camera object to this, you would then add a child to this parent object that is the 'model' of the player, you would rotate this object. That way, the movement is coupled with both the model + camera, but the rotation is only tied to the model. – mGuv Jun 25 '15 at 16:23
-
I don't want the camera on the player but on a distance of +-10 – user5049500 Jun 25 '15 at 17:32
-
If the camera is attached as it's own object, you can position it where ever you want and it will stay relative to the player. – mGuv Jun 25 '15 at 18:47
-
Thanks for the help, everything works now. – user5049500 Jun 25 '15 at 20:16
2 Answers
0
You need to create a script and add it to your camera.
public GameObject player = GameObject.Find("Player");
this.transform.position = new Vector3(player.transform.position.x, player.transform.position.y, transform.position.z);
So your player is always in center of your camera.

Blair
- 6,623
- 1
- 36
- 42

Yaşarcan Kasal
- 41
- 3
-
I tried you code, but it just places the camera on the ball (this is good), but when I move the ball, the camera doesn't follow. – user5049500 Jun 25 '15 at 17:01
-
-
I did that, it something with photon i think. But it's ok now, i used mGuv's advice. Thanks to – user5049500 Jun 26 '15 at 11:29
0
You should add this piece of code.
GameObject player;
Vector3 cameraOffset;
void Start()
{
player = GameObject.Find("Player");
cameraOffset = new Vector3(0f, 0f, 0f)
}
void Update()
{
transform.position = new Vector3(player.transform.position.x + cameraOffset.x, player.transform.position.y + cameraOffset.y, player.transform.position.z + cameraOffset.z);
}
and attach it to you camera's script. I put the Offset as (0,0,0) but you should set an offset so your camera doesn't go inside of your player GameObject, but the amount is up to your criteria.

RJD
- 48
- 1
- 7