Ok, so I have a little character dude and I’ve set him up to move with WSAD keys. It’s a top-down RPG, for the visual.
if(Input.GetKey(KeyCode.W)){
transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime, Space.World);
transform.LookAt (Vector3.forward);
}
if(Input.GetKey(KeyCode.S)){
transform.Translate (-Vector3.forward * moveSpeed * Time.deltaTime, Space.World);
transform.LookAt (-Vector3.forward);
}
if(Input.GetKey(KeyCode.A)){
transform.Translate (Vector3.left * moveSpeed * Time.deltaTime, Space.World);
transform.LookAt (Vector3.left);
}
if(Input.GetKey(KeyCode.D)){
transform.Translate (Vector3.right * moveSpeed * Time.deltaTime, Space.World);
transform.LookAt (Vector3.right);
}
So obviously I’m using transform.LookAt wrong, because I realize that just points to the point in world space which just kind of makes him twitch and look to the one area. I was previously using a click-move system but that was really getting on my nerves so I changed it up to this, but now I’m not quite sure how to go about making the character face the correct direction he’s moving. I mean there are only 8 directions it’s possible for him to move, so I could hard code all eight possibilities with exact angles… But that’s a bit constrictive and I’m trying to be more thoughtful about my code so I figure instead of having 8 separate checks going on every Update(), I could just point him in his current direction once?