- Home /
No movement to negative z-axis.
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);
}
}
Having a child game object with an active collider on the character is the usual reason for this behavior. Not sure that is the problem here.
Answer by Kitai · Feb 21, 2014 at 09:03 AM
Uh, I noticed this from other discussions like this and in my case that wasn't the problem. I think I provided too little information because it finally wasn't my script that was wrong but what I had within my object. So, I started to create my character by adding a First Person Controller prefab from standard assets. Then I deleted Mouse Look from both camera and the parent object and added my script to parent object. This was almost ok. What I also needed to do was to delete the FPSInput Controller and Character Motor scripts. Now I know that starting from the prefab was totally unnecessary (and actually little stupid too.. :|), better to just create camera+object and put these inside of an empty object and attach the script. But what matters the most is that now everything is working beautifully :) That you robertbu for your attempt to help! :)