- Home /
Mouse orbit cam network player?
Okay, so i'm trying to make a multi-player RPG. After getting network connections working from a tutorial I found, I have ran into a frustrating problem.
The tutorial gave me a FPS type camera, and I love how it's set up!
if(Input.GetMouseButton(1))
{
Camera.main.transform.Rotate(0,(Input.GetAxis("Mouse X") * 5.0F),10);
Camera.main.transform.Rotate((-Input.GetAxis("Mouse Y") * 5.0F),0,0);
}
I am going to college for this field, and along the way we've learned an extensive amount of math. I'm looking to make a bit of code for inside of this block that will access the Camera.main.transform.translate within the current transform's code!
For example:
The equation of a sphere is R^2=[(X-A)^2+(Y-B)^2+(Z-C)^2]
Where A=sphere's X center point B=sphere's Y center point C=sphere's Z center point
All of which are the player's location or center point.
My code came out as follows:
if(Input.GetMouseButton(1))
{
Camera.main.transform.Translate(((Input.GetAxis("Mouse X")-transform.position.x)*(Input.GetAxis("Mouse X")-transform.position.x))/2,
((Input.GetAxis ("Mouse Y")-transform.position.y)*(Input.GetAxis ("Mouse Y")-transform.position.y))/2,
((Input.GetAxis("Mouse Z")-transform.position.z)*(Input.GetAxis("Mouse Z")-transform.position.z))/2);
//Camera.main.transform.Rotate(0,(Input.GetAxis("Mouse X") * 5.0F),10);
//Camera.main.transform.Rotate((-Input.GetAxis("Mouse Y") * 5.0F),0,0);
}
Am I doing this correctly? I still need to couner-act the sphereical transformation with a sphereical rotation to keep my camera looking at the player.
I've played around with converting the mouse-orbit scripts from the "main camera" to the "player" gameObject mesh; however it affected the "server" main camera, and actually allowed me to move every single player connected with the server client AND the player client.
The Real Question is: How does one create a mouse orbit camera function around a "transform" when accessing Camera.main.transform from within the "transform"'s code?
maybe I forgot to mention a few things...
The scene only has a camera object
the scene starts a network file which parents the camera to the player for player movement
If I add a player to network there will always be a dud player started by the server
If I add camera orbit to the network player script(above) it allows the server client to move all objects inside the server (only players connected are rendered at this point)
Your answer
Follow this Question
Related Questions
Send RPC in 2 scene 0 Answers
Network.Destroy and collision; destroying correct object. 1 Answer
Fatal Error when opening Unity 1 Answer
[Solved] How do use same code in single-player AND multi-player? 0 Answers
RPC calls client to server Errors 1 Answer