Ok, so I wanted to do a third person camera so I went over to 3dbuzz to play with their demo videos and basically make one line for line from their video. I got it all working. camera works pretty good but my problem is.. The basic movement of the character controller is not working.. I must admit.. the basics here are so simple so I am not even sure why its not working.. So, I go about using their simple code.. Code (CSharp): var deadZone = 0.1f; TP_Motor.Instance.MoveVector = Vector3.zero; float ForwardOrBackword = Input.GetAxis ("Vertical"); float RightOrLeft = Input.GetAxis ("Horizontal"); //if (Input.GetAxis("Vertical") > deadZone || Input.GetAxis("Vertical") < -deadZone) TP_Motor.Instance.MoveVector += new Vector3(0f,0f,ForwardOrBackword); //if (Input.GetAxis("Horizontal") > deadZone || Input.GetAxis("Horizontal") < -deadZone) TP_Motor.Instance.MoveVector += new Vector3(RightOrLeft,0f,0f); if (MoveVector.x != 0 || MoveVector.z != 0) { transform.rotation = Quaternion.Euler( transform.eulerAngles.x, Camera.main.transform.eulerAngles.y, transform.eulerAngles.z); } //Transform MoveVecctor to WorldSpace MoveVector = transform.TransformDirection(MoveVector); //Normalize MoveVector if Magnitude > 1 if (MoveVector.magnitude > 1) MoveVector = Vector3.Normalize(MoveVector); //Multiple MoveVector by MoveSpeed MoveVector *= MoveSpeed; //Convert Units/Frame to Units/Spec //Multiply MoveVector by Delta Time.. MoveVector *= Time.deltaTime; //Move Character in WorldSpace. TP_Controller.CharacterController.Move(MoveVector); I went ahead and slimmed it down some.. But does anyone see any major issues with the script that stick out that I may be missing ?
Hi shawndg It's a bit hard to tell, since your code looks a bit like a mixture between TP_Controller and TP_Motor. I also can't tell the context of the snippet. E.g. if the snippet is placed within Update() in TP_Controller. However, here are some thoughts, based on my own implementation (I did the same as you and went through the 3dbuzz tutorial (-: ): In my implementation the part TP_Motor.Instance.MoveVector += new Vector3(0f,0f,ForwardOrBackword); is in TP_Controller and within Update(). But I don't work with variables (like "ForwardOrBackword") but rather with Input.GetAxis("Vertical") I have no such thing as in lines 13 - 21, so I can't give you any recommendation on that (-; Lines 23-38 look (quite) the same as in my code in TP_Motor. Only difference is that I have applied gravity and vertical velocity. But that won't make any difference to your problem. Therefore, I'd guess that the issue is somewhere in lines 4 - 11. However, depending in which context (Update() etc.) you are using them. Hope it helps (-:
Ok, I went back to what I think is the original code based off the tutorial and problem is still occurring. Code (CSharp): using UnityEngine; using System.Collections; public class TP_Controller : MonoBehaviour { public static CharacterController CharacterController; public static TP_Controller Instance; void Awake() { CharacterController = GetComponent("CharacterController") as CharacterController; Instance = this; TP_Camera.UseExistingOrCreateNewMainCamera(); } void Update() { //if (Camera.main == null) //return; GetLocomotionInput(); TP_Motor.Instance.UpdateMotor (); } void GetLocomotionInput() { var deadZone = 0.1f; TP_Motor.Instance.MoveVector = Vector3.zero; if (Input.GetAxis("Vertical") > deadZone || Input.GetAxis("Vertical") < -deadZone) TP_Motor.Instance.MoveVector += new Vector3(0f,0f,Input.GetAxis ("Vertical")); if (Input.GetAxis("Horizontal") > deadZone || Input.GetAxis("Horizontal") < -deadZone) TP_Motor.Instance.MoveVector += new Vector3(Input.GetAxis ("Horizontal"),0f,0f); } } Code (CSharp): using UnityEngine; using System.Collections; public class TP_Motor : MonoBehaviour { public static TP_Motor Instance; public float MoveSpeed = 10f; public Vector3 MoveVector { get; set; } void Awake () { Instance = this; } public void UpdateMotor () { SnapAlignCharacterWithCamera(); ProcessMotion (); } void ProcessMotion() { //Transform MoveVecctor to WorldSpace MoveVector = transform.TransformDirection(MoveVector); //Normalize MoveVector if Magnitude > 1 if (MoveVector.magnitude > 1) MoveVector = Vector3.Normalize(MoveVector); //Multiple MoveVector by MoveSpeed MoveVector *= MoveSpeed; //Convert Units/Frame to Units/Spec //Multiply MoveVector by Delta Time.. MoveVector *= Time.deltaTime; //Move Character in WorldSpace. TP_Controller.CharacterController.Move(MoveVector); } void SnapAlignCharacterWithCamera() { if (MoveVector.x != 0 || MoveVector.z != 0) { transform.rotation = Quaternion.Euler( transform.eulerAngles.x, Camera.main.transform.eulerAngles.y, transform.eulerAngles.z); } } } Camera is pretty decent though, but movement is just all over the place.. And the logic makes perfect sense so I am wondering if maybe its my character or input settings..
Still having problems here, I rewrote most of this and the problem is the same.. I cant click w or up to move forward... I got all other directions working properly.. very confused now..
I got it all working... The problem was my player object, I had a child on it that had a collider on it and it was colliding with my parent object whenever I tried to move forward... OMG that was a pain to figure it out.. Posting this so if anyone else runs into this odd issue,..