Hello everyone i’m a new on Unity, i was just wondering how can i put mouselook on my thirdperson character, i found a lot of tutorials but they are all outdated since i have Unity 5.1.3 (free version), i already put a camera on my character but he only see horizontal but i want indeed that the character is able to look all the way around,how can i do?
Old tutorials typical work btw(with some editing) and try this (may not work intended for a top down game)
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour {
public int rotationSpeed = 520;
public float walkSpeed = 5;
public float runSpeed;
private Quaternion targetRotation;
private CharacterController controller;
private Camera camera;
public Gun gun;
void Start()
{
controller = GetComponent();
camera = Camera.main;
}
void Update()
{
//ControlMouse();
ControlWASD();
if (Input.GetButtonDown(“Shoot”))
{
gun.Shoot();
}
else if (Input.GetButton(“Shoot”))
{
gun.ShootAuto();
}
}
void ControlWASD()
{
Vector3 input = new Vector3(Input.GetAxis(“Horizontal”), 0, (Input.GetAxis(“Vertical”)));
if (input != Vector3.zero)
{
targetRotation = Quaternion.LookRotation(input);
transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle(transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeed * Time.deltaTime);
}
Vector3 motion = input;
motion *= (Mathf.Abs(input.x) == 1 && Mathf.Abs(input.z) == 1) ? .7f : 1;
motion *= (Input.GetButton(“Run”)) ? runSpeed : walkSpeed;
motion += Vector3.up * -8;
controller.Move(motion * Time.deltaTime);
}
void ControlMouse()
{
Vector3 mousePos = Input.mousePosition;
mousePos = camera.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, camera.transform.position.y - transform.position.y));
targetRotation = Quaternion.LookRotation(mousePos - new Vector3(transform.position.x, 0, transform.position.z));
transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle(transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeed * Time.deltaTime);
Vector3 input = new Vector3(Input.GetAxisRaw(“Horizontal”), 0, (Input.GetAxisRaw(“Vertical”)));
Vector3 motion = input;
motion *= (Mathf.Abs(input.x) == 1 && Mathf.Abs(input.z) == 1) ? .7f : 1;
motion *= (Input.GetButton(“Run”)) ? runSpeed : walkSpeed;
motion += Vector3.up * -8;
controller.Move(motion * Time.deltaTime);
}
}
Oh jeez sorry you can ignore the Update method
Oh sorry, i don’t mentioned that the game is a Third Person RPG btw still doesn’t work 'cause he reports “Gun” and similars as errors
Edit 1: I’m also newbie in all that stuff like C# o JS