- Home /
Question by
Mami27 · Aug 13, 2015 at 06:40 PM ·
cameranetworkingmousepositionnewlook
Input.mousePosition for new networking
I use new networking system and i have some problems. here is
|
v
my player look all clients mouse
my code:
public float speed;
void Start(){
if(isLocalPlayer)
GameObject.Find("Main Camera").GetComponent<Camera2DFollow>().target = transform;
}
void Update () {
if (!isLocalPlayer)
return;
CmdLookMouse ();
CmdWalk (0);
if (Input.GetMouseButton (0))
CmdWalk (speed);
}
[Command]
void CmdWalk(float speed){
Rigidbody2D rigidbody2d = GetComponent<Rigidbody2D>();
rigidbody2d.velocity = transform.TransformDirection (Vector2.up * speed);
}
[Command]
void CmdLookMouse(){
Vector3 difference = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
float rot_z = Mathf.Atan2 (difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler (transform.rotation.x, transform.rotation.y, rot_z - 90);
}
Comment
Your answer
Follow this Question
Related Questions
Make object follow mouse, while actually moving camera, instead of object 2 Answers
weapon bob when looking 2 Answers
how to find mouse look 1 Answer
Spawning problems with cameras 1 Answer