Alright, so the Move() function of the character controller has me stumped. I have a little capsule in my scene and I just wanted to get it moving around, so I wrote the code below. Here’s the thing - when I press any two directions (up and right, left and up, etc), the Move() function of the CharacterController starts changing the y values of the character’s position. I cannot for the life of me figure out why this is happening. Using transform.position += does not yield the same problem. Any help would be MUCH appreciated.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class DummyPlayer : MonoBehaviour {
protected CharacterController myCharacterController;
void Start () {
myCharacterController = this.GetComponent<CharacterController>();
}
void Update () {
ProcessInput();
}
private void ProcessInput()
{
float analogZ = Input.GetAxis("Vertical");
float analogX = Input.GetAxis("Horizontal");
Vector3 moveVect = new Vector3(analogX, 0, analogZ);
if(moveVect.y != 0 || this.transform.forward.y != 0)
{
Debug.Log(moveVect.y + " " + this.transform.forward.y); //never called
}
//this.transform.position += moveVect*Time.deltaTime*40f;
myCharacterController.Move(moveVect*Time.deltaTime*40f); //why does this affect my y value when the line commented out above doesn't?
}
}
Also, the variables are named analogX and analogZ because eventually I’d like to get input from a joystick - for now I’m just using the keyboard.
UPDATE:
So after some experimenting around with project settings, I added the following lines to the end of my ProcessInput() function:
if(myCharacterController.collisionFlags != CollisionFlags.None)
{
Debug.Log("I understand nothing anymore.");
}
then ran the program. When I perform the steps necessary to recreate my original problem, every few updates, I see the Debug statement in the console. Mind you, that aside from the default camera Unity adds when you start a project, I have nothing in the scene except for my childless, parentless capsule. I cannot fathom how it is colliding with itself. Please help!