Question by
iclementush · Aug 10, 2016 at 06:49 PM ·
charactercharacter movementmouse movement
need character to move with mouse look movement.
**I made a mouse movement script, so I can look around with the mouse, but as soon as I move with my character, all the mouse movements gets changed, how do I make my character to move with how I look ? mouse look movement : using UnityEngine; using System.Collections; public class MouseLook : MonoBehaviour { Vector2 mouseLook; Vector2 smoothV; public float sensitivity = 5.0f; public float smoothing = 2.0f; GameObject character; void Start () { character = this.transform.parent.gameObject; }
void Update ()
{
var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
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);
character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
var md2 = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
}
}**
Comment