NOTE: I don’t want to go into the Unity Asset store and buy a third person camera or movement script because I learn nothing by doing that.
What I want to do is create simple third person movement and camera controls similar to what you’d see in an action game like, say, Dark Souls. The problem I’ve been having is that the attempts I’ve made previously are flawed practically from a conceptual level. For movement I used something as simple as this:
public class PlayerScript : MonoBehaviour
{
Vector3 directionVector;
const float SPEED = 1.5f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0)
{
directionVector.x = Input.GetAxis("Horizontal") * Time.deltaTime * SPEED;
directionVector.z = Input.GetAxis("Vertical") * Time.deltaTime * SPEED;
transform.eulerAngles = new Vector3(0, Vector3.Angle(Vector3.forward, directionVector), 0);
}
else
{
directionVector = Vector3.zero;
}
}
// Called after Update
void LateUpdate()
{
}
}
Which works as far as movement goes, but is ultimately useless if the camera doesn’t follow. I THOUGHT it’d be as simple as just making the camera a child of the character model and while it certainly SEEMS like it works, the problem is that the controls feel unnatural. If you turn and move sideways, for instance, it feels like you should be pressing W or the up key to move forward, but you don’t because the input controls are ultimately tied to world coordinates and are not relative to the direction the character is already facing. And worse yet is that, even if I WERE to find a way to make the input controls move the character relative to the direction they are currently facing, I feel it wouldn’t be right or “professional”. So, down to the very philosophy behind simple third person movement/camera controls in action games, how does this work?