Hey guys im trying to make a multiplayer mouselook script but the only problem i have right now is that my capsule also gets rotated but i only want my camera to rotate like it should, my script is attached to my capsule because otherwise it will move all characters... Code (csharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class camMouseLook : NetworkBehaviour { Vector2 mouseLook; Vector2 smoothV; public float sensitivity = 5.0f; public float smoothing = 2.0f; public Camera cam; private void Start() { } void Update() { if (!isLocalPlayer) { return; } var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxis("Mouse Y")); md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing)); smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing); smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing); mouseLook += smoothV; mouseLook.y = Mathf.Clamp(mouseLook.y, -90f, 90f); transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right); cam.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, cam.transform.up); } }
If you don't want to rotate the capsule, and you have this script attached to the capsule, don't modify transform.localRotation on line 37. If you want to rotate the camera then you would do all your rotations to cam.transform.localRotation like you're doing on line 38.
Why would making it negative stop it from happening? Just remove the entire line. You're setting your localRotation, so of course your capsule is rotating.
Ohhhh... Try using RotateAround instead. RotateAround lets you specify which (local) axis you rotate around.
That made my character space around and rotate every axis could you please edit my code to where it should work??
That sounds like you're still messing with the object's own transform instead of the camera's transform. If your code starts with "transform" instead of "cam.transform" you're having your script manipulate the capsule instead of the camera. See your own previously posted code. On line 37 you are modifying "transform.rotation", transform refers to the object the script is attached to, which is the capsule. On line 38 you are modifying "cam.transform.rotation", which instead of the capsule's transform you are modifying the transform of the camera. So whatever you are doing, you want to manipulate "cam.transform" not "transform". get it?
I get that but i want my capsule to transform on it's x axis but not on it's Y axis that's why i wrote -Mouselook.y but it still uses it's y axis..