To see if using the rigidbody's "constrain rotation" feature would work. I removed the rigidbody and tried to see if it'll work again..still doesn't. Ugh.
Here's the character script, if it helps:
using UnityEngine;
using System.Collections;
public class DungeonPlayerBehaviorScript : MonoBehaviour {
private const float VELOCITY = 40;
private const float ROTATION_SPEED = 1024.0f; // Degrees per second
private CharacterController controller;
private Vector3 direction;
private tk2dSpriteAnimator animator;
private Quaternion qTo;
private bool joystickConnected;
void Start () {
//ONLY FOR TESTING PURPOSES
//TODO: Make multiplayer-compatible joystick and input system
if (Input.GetJoystickNames ().Length > 0) {
joystickConnected = true;
} else {
joystickConnected = false;
}
animator = GetComponent<tk2dSpriteAnimator>();
Light2D.RegisterEventListener (LightEventListenerType.OnEnter, onBeamEnter);
}
void Update () {
updateFrameVariables();
if (joystickConnected) {
joystickMovementUpdate();
} else {
keyboardMovementUpdate();
}
if (controller.velocity.sqrMagnitude > 0) {
animator.Play ("forward");
} else {
animator.Play ("idle");
}
}
private void joystickMovementUpdate() {
if (direction.sqrMagnitude > 0.1f) {
qTo = Quaternion.LookRotation(direction);
qTo.eulerAngles = new Vector3(90, qTo.eulerAngles.y + 90, 0);
}
transform.eulerAngles = new Vector3(90, transform.eulerAngles.y,0);
transform.rotation = Quaternion.RotateTowards(transform.rotation, qTo, ROTATION_SPEED * Time.smoothDeltaTime);
controller.Move (new Vector3(Input.GetAxis ("Left Joystick Horizontal") * VELOCITY, 0, -Input.GetAxis ("Left Joystick Vertical") * VELOCITY) * Time.smoothDeltaTime);
}
private void keyboardMovementUpdate() {
transform.LookAt (Camera.main.ScreenToWorldPoint (Input.mousePosition));
controller.Move (new Vector3(Input.GetAxis ("Keyboard Horizontal") * VELOCITY, 0, Input.GetAxis ("Keyboard Vertical") * VELOCITY) * Time.smoothDeltaTime);
}
private void updateFrameVariables() {
controller = GetComponent<CharacterController>();
direction = new Vector3(Input.GetAxis ("Right Joystick Horizontal"), 0, Input.GetAxis ("Right Joystick Vertical"));
}
void onBeamEnter(Light2D light, GameObject go) {
Debug.Log (go.tag);
if (go.CompareTag ("Mob One")) {
go.GetComponent<MobOneBehaviorScript> ().State = 1;
}
}
void LateUpdate()
{
Camera.main.transform.position = new Vector3(transform.position.x, 2, transform.position.z);
}
}