Hi,
I’m working with this 3D top down shooter game and try to get my character to look to the direction it’s moving. I’m using joystick as a controller. Now it’s looking where it should be going but not going there, not at least if the direction is negative z-axis. Any ideas?
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (CharacterController))]
public class JoystickLook : MonoBehaviour {
public float speed = 10f;
private CharacterController controller;
private Vector3 input = Vector3.zero;
private Vector3 motion = Vector3.zero;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
input = new Vector3 (Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
input = input.normalized;
if (input != Vector3.zero) {
transform.rotation = Quaternion.LookRotation(input);
}
motion = input;
motion *= speed;
Debug.Log (motion);
controller.Move (motion * Time.deltaTime);
}
}