- Home /
Question by
rajannath · Aug 16, 2018 at 06:56 AM ·
1st person
my script not working in touch method
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FpsCamera : MonoBehaviour {
private Vector2 mouseLook;
private float swipeResistence = 200;
Vector2 smoothV;
public float sentitivity = 5.0f;
public float smoothing = 2.0f;
GameObject character;
// Use this for initialization
void Start ()
{
character = this.transform.parent.gameObject;
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown (0))
{
var md = new Vector2 (Input.GetAxis ("Vertical"), Input.GetAxis ("Horizontal"));
md = Vector2.Scale (md, new Vector2 (sentitivity * smoothing, sentitivity * smoothing));
smoothV.x = Mathf.Lerp (smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp (smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV;
transform.localRotation = Quaternion.AngleAxis (-mouseLook.x, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis (mouseLook.y, character.transform.up);
}
}
}
Comment
Answer by rajannath · Aug 16, 2018 at 06:58 AM
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FpsCamera : MonoBehaviour {
private Vector2 mouseLook;
private float swipeResistence = 200;
Vector2 smoothV;
public float sentitivity = 5.0f;
public float smoothing = 2.0f;
GameObject character;
// Use this for initialization
void Start ()
{
character = this.transform.parent.gameObject;
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown (0))
{
var md = new Vector2 (Input.GetAxis ("Vertical"), Input.GetAxis ("Horizontal"));
md = Vector2.Scale (md, new Vector2 (sentitivity * smoothing, sentitivity * smoothing));
smoothV.x = Mathf.Lerp (smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp (smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV;
transform.localRotation = Quaternion.AngleAxis (-mouseLook.x, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis (mouseLook.y, character.transform.up);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612172915im_/https://answers.unity.com/themes/thub/images/avi.jpg)