Question by
mik_dass · Dec 27, 2016 at 07:43 PM ·
third person controllerthird-person-camera
Help with the third person controller script
I am trying to make a third person shooter in which the movement of the mouse moves the crosshair and also rotates the character . The script works somewhat but if I move forward or turn around the firing action (input) is not getting triggered and while moving or turning I cannot look up or down,so basically the mouse input freezes. Here is my script:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
Animator anim;
private float inputv;
private float inputh;
Rigidbody rbody;
public float speed_walk;
public float speed_run;
public float speed_turn;
public float pitch_MAX;
public float pitch_MIN;
private float yaw = 0.0f;
private float pitch = 0.0f;
public float speedH = 2.0f;
public float speedV = 2.0f;
CharacterController character;
// Use this for initialization
void Start () {
anim = transform.GetComponent<Animator> ();
rbody = transform.GetComponent<Rigidbody> ();
character = transform.GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(0)){
print ("DONE");
anim.Play ("assault_combat_shoot",-1,0.0f);
}
inputv = Input.GetAxisRaw ("Vertical");
inputh = Input.GetAxisRaw ("Horizontal");
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
anim.SetFloat ("inputv",inputv);
float movez = inputv * 5f;
float movex = inputh * speed_turn;
//transform.Rotate (new Vector3(0.0f,movex,0.0f));
yaw += movex;
transform.eulerAngles = new Vector3(Mathf.Clamp(pitch,pitch_MIN,pitch_MAX), yaw, 0.0f);
if (movez > 0) {
Vector3 vec = transform.forward;
vec.y = 0;
rbody.velocity = vec*speed_walk;
} else {
rbody.velocity = Vector3.zero;
}
Vector3 movement = new Vector3 ();
}
}
I want to know what is locking the camera movement and firing while running or turning.
Comment